From 335ee4aa2b25f315f05142b0c9853ead6cb8758c Mon Sep 17 00:00:00 2001 From: esoe Date: Wed, 9 Nov 2022 08:50:39 +0300 Subject: [PATCH] qq --- pom.xml | 4 +- .../molokoin/sourceListener/HttpClient.java | 57 ------------------ .../sourceListener/SourceListener.java | 33 ++++++---- .../molokoin/sourceListener/HttpClient.class | Bin 2819 -> 0 bytes .../sourceListener/SourceListener.class | Bin 872 -> 2188 bytes 5 files changed, 23 insertions(+), 71 deletions(-) delete mode 100644 src/main/java/ru/molokoin/sourceListener/HttpClient.java delete mode 100644 target/classes/ru/molokoin/sourceListener/HttpClient.class diff --git a/pom.xml b/pom.xml index a78af89..a406b19 100644 --- a/pom.xml +++ b/pom.xml @@ -12,8 +12,8 @@ 1.0 jar - 17 - 17 + 11 + 11 UTF-8 diff --git a/src/main/java/ru/molokoin/sourceListener/HttpClient.java b/src/main/java/ru/molokoin/sourceListener/HttpClient.java deleted file mode 100644 index 766c927..0000000 --- a/src/main/java/ru/molokoin/sourceListener/HttpClient.java +++ /dev/null @@ -1,57 +0,0 @@ -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 b83bfc9..d729cde 100644 --- a/src/main/java/ru/molokoin/sourceListener/SourceListener.java +++ b/src/main/java/ru/molokoin/sourceListener/SourceListener.java @@ -1,20 +1,29 @@ package ru.molokoin.sourceListener; +import java.net.URI; +import java.net.http.HttpClient; +import java.net.http.HttpRequest; +import java.net.http.HttpResponse; + public class SourceListener { public static void main(String[] args) { - 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()); + HttpClient client = HttpClient.newHttpClient(); + HttpRequest request = HttpRequest.newBuilder() + .uri(URI.create("http://molokoin.ru:3000/esoe/molokoin-client")) + .GET() // GET is default + .build(); + + try { + HttpResponse response = client.send(request, + HttpResponse.BodyHandlers.ofString()); + System.out.println(response.statusCode()); + System.out.println(response.headers()); + System.out.println(response.body()); + } catch (Exception e) { + System.out.println(e.getMessage()); + } + } } diff --git a/target/classes/ru/molokoin/sourceListener/HttpClient.class b/target/classes/ru/molokoin/sourceListener/HttpClient.class deleted file mode 100644 index b98227d0875d830db9b753a7ddcf014e5bf7feac..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 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 diff --git a/target/classes/ru/molokoin/sourceListener/SourceListener.class b/target/classes/ru/molokoin/sourceListener/SourceListener.class index ef803fed8129a7bb76a74e361c9c29ed3a8991bf..fe756fdc7e14137d76d170054d5f42b474fdceeb 100644 GIT binary patch literal 2188 zcma)7U0V}J6n+N+17T75ECSkMK@+|f#nzS}wo(+@fD{m0X=yiM3=7F_+})`BqF&nz z3SRW-b$?XbcXk6LxcKyDzRsEVob%2(Xa4@@-JbyN;XtB6AnjGml3R55UE48zx8mhh z*7gJCD9>E4+e#z^uIyQ_EVF1i1@lR6PvrxF=2_dZgE@i5RC-e&G4JlEBpT6bpb5@$_mK(jZ_RrXHoJ-rVS&wC2><==oIOc zuyc+YNFmKfuXwh=bQN3ErGetuJ9j@cHfCU4^VIlwVM80AG+<&%ped(G6S(#v%J>j> za93hl;8vWwe%W<=HT=-sIasuuoucx51E1k@ffn~glq3S97g%`zGR<}13j<$bhKc7Z zhyGbLai1qDbH;6rC@cBz~;tDeMFqe@o;4bPm6!QEcN^iC<144KWwq~d9Z!7#b2gHNVAas)h}FIxSo!^Bs~mQ83D!q4`a&Mry6tz>|0k0= zso1lY9R4-)Ma%aUsgu<{DDg_*=EX@{Th;xs`tY1uI;6W~fNmp? z9nJ|ngTjl@(gPH*OOE&jz{VZ}T&2~06uBxvY@#Y6&CVq&UZM!LF<40Tti&| 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 zWcyZ452aBBJ