From f33ca43cdc15682368c64782796757ed908eeefc Mon Sep 17 00:00:00 2001 From: esoe Date: Tue, 8 Nov 2022 21:37:15 +0300 Subject: [PATCH] qq --- pom.xml | 4 +- .../molokoin/sourceListener/HttpClient.java | 57 ++++++++++++++++++ .../sourceListener/SourceListener.java | 14 ++++- .../molokoin/sourceListener/HttpClient.class | Bin 0 -> 2819 bytes .../sourceListener/SourceListener.class | Bin 700 -> 872 bytes 5 files changed, 72 insertions(+), 3 deletions(-) create mode 100644 src/main/java/ru/molokoin/sourceListener/HttpClient.java create mode 100644 target/classes/ru/molokoin/sourceListener/HttpClient.class diff --git a/pom.xml b/pom.xml index 7b1b855..a78af89 100644 --- a/pom.xml +++ b/pom.xml @@ -12,8 +12,8 @@ 1.0 jar - 18 - 18 + 17 + 17 UTF-8 diff --git a/src/main/java/ru/molokoin/sourceListener/HttpClient.java b/src/main/java/ru/molokoin/sourceListener/HttpClient.java new file mode 100644 index 0000000..766c927 --- /dev/null +++ b/src/main/java/ru/molokoin/sourceListener/HttpClient.java @@ -0,0 +1,57 @@ +package ru.molokoin.sourceListener; +import java.net.*; +import java.io.*; + +/** + * This program demonstrates a client socket application that connects to + * a web server and send a HTTP HEAD request. + * + * @author www.codejava.net + */ +public class HttpClient { + URL url; + + public static void main(String[] args) { + HttpClient cli = new HttpClient(); + try { + cli.url = new URL("http://www.molokoin.ru"); + } catch (MalformedURLException ex) { + ex.printStackTrace(); + return; + } + + String hostname = cli.url.getHost(); + int port = 3000; + + try (Socket socket = new Socket(hostname, port)) { + + OutputStream output = socket.getOutputStream(); + PrintWriter writer = new PrintWriter(output, true); + + writer.println("HEAD " + cli.url.getPath() + " HTTP/1.1"); + writer.println("Host: " + hostname); + writer.println("User-Agent: Simple Http Client"); + writer.println("Accept: text/html"); + writer.println("Accept-Language: en-EN"); + writer.println("Connection: close"); + writer.println(); + + InputStream input = socket.getInputStream(); + + BufferedReader reader = new BufferedReader(new InputStreamReader(input)); + + String line; + + while ((line = reader.readLine()) != null) { + System.out.println(line); + } + } catch (UnknownHostException ex) { + + System.out.println("Server not found: " + ex.getMessage()); + + } catch (IOException ex) { + + System.out.println("I/O error: " + ex.getMessage()); + } + } +} diff --git a/src/main/java/ru/molokoin/sourceListener/SourceListener.java b/src/main/java/ru/molokoin/sourceListener/SourceListener.java index 0bec7da..b83bfc9 100644 --- a/src/main/java/ru/molokoin/sourceListener/SourceListener.java +++ b/src/main/java/ru/molokoin/sourceListener/SourceListener.java @@ -1,8 +1,20 @@ package ru.molokoin.sourceListener; public class SourceListener { + public static void main(String[] args) { - System.out.println(Thread.currentThread().getName()); + HttpClient client = HttpClient.newBuilder() + .version(Version.HTTP_1_1) + .followRedirects(Redirect.NORMAL) + .connectTimeout(Duration.ofSeconds(20)) + .proxy(ProxySelector.of(new InetSocketAddress("www.ya.ru", 80))) + .authenticator(Authenticator.getDefault()) + .build(); + + +HttpResponse response = client.send("GET", BodyHandlers.ofString()); +System.out.println(response.statusCode()); +System.out.println(response.body()); } } diff --git a/target/classes/ru/molokoin/sourceListener/HttpClient.class b/target/classes/ru/molokoin/sourceListener/HttpClient.class new file mode 100644 index 0000000000000000000000000000000000000000..b98227d0875d830db9b753a7ddcf014e5bf7feac GIT binary patch literal 2819 zcma)8?N=Pt8UJ0_Wro>-1jq|ZBv~~iKmwc8*A7+<5ev#onkAu|Saq^{feE`ao7vfr zRO|b@ty)`c)wWiTJ$&#}dfKH&POP7d$4{Q)Kj430Kl`EdcV}2w50<;ZpdnxbjJ1r19?&YO{MkGvV z&;_=QJFc9p6wgV2+CEp10`22o&Mus`eMfz-ZN`Fmrz~)A{QruPeq%-3aRqkuo{b_3 zW6cD<~cSG=E64XRb zsxSm!+C_oRnk&ak*Gq;pqy;)ccNCpaVbAzZAbkUaII3L!NT6%Y<@L&E`c7-OU0`>p zUx&zW#VO>auj5XE_~^*72T}%ZL#Il^k4;#$G@P)5c_p~VBxgyfCc9LUZeCzui#y(! zt2Hk}I_?)}PK{1apGY4aJgO`Xn>en#=z$k;L|tdZ#DfZLEkvi_>KLU@g@u*U@esj1 zRhIt1u{lNr7_I4Ms=k!NRDc1{9vtGr`TV(BJJfY#20^MOo!#3zHxZa|xXj51APpWtg0ysfm#9zl#>_}tj zsg(46&sV0NQKp`)1+0=jwQhj@&GzTm5IeSLZ%k*dz;rdpO9H7Vrz(;yI}lr?KF`=( zyBPM~>q}F$(vs&B9Wh4sm&5)-j&7KZT8?V<1d(hc)z)#`)H`@$G3*sLARV<3nut4! z&-LMa%8dq1^0atp1tPo5F?(nQ9ohDs z%h>%-bS{4?mN! ze_Qcn>>7+@+=?xsEg4J3|HdyaRg{!CMtk8EE;7VqtcpvuFz1%AZ$td6HSyEy;w#Lk zj-BY_xF5o|_>LJrg75hQ^ov%}%66dE0oHP($~|1{;d2|c+Njr#Bqv-qc3>}d;{fgS zql=bq!Z3Fyv5)6dc%HO)4Y%O8{D0t&*pCm{+&;lUe2P9?#Q?tGaQKSrw>ToUbNmi) z#HKk($8dMZh&RXuqK@Zi3G9f&c!3eH=`;El@e(O^K8K_jOp<0 z4~X#&z*8_+dEEvL?`aH0Xy}fw;v<;RhKBdKbs_xi(eNh?gBt##VTJFul$I literal 0 HcmV?d00001 diff --git a/target/classes/ru/molokoin/sourceListener/SourceListener.class b/target/classes/ru/molokoin/sourceListener/SourceListener.class index 26f08ca7a2c2f0ca5af254dc99f56df42a6ff981..ef803fed8129a7bb76a74e361c9c29ed3a8991bf 100644 GIT binary patch literal 872 zcma)4!EO^V5FMv!(lv#Kloq&|TT&$UP64ScpdzgRH6;?_J3t%mahg6K!;O#$ct_A2MhjScM!`AX$f1XffExw87VPIYM_V zM+GwIW;U0_P&ys+%VIN(wP)}!ySAWRx~!DiFxc*W$QHr|!D(~4+aI>!HeJ7Hyl~FC zHP~eA^E>0v+hT%Bv8e@YPq4;xQutJK-<@7u`LZuzOV zH!DxxI{Rrlz=Ehq)H1{?gJEFva}0Y*ksQASC1&d4I6T>_X*3gbF8{?CCq6=7S>y3P zWcyZ452aBBJVcyEmCF}Kl`~n