{"id":10194,"date":"2015-08-25T00:00:08","date_gmt":"2015-08-25T04:00:08","guid":{"rendered":"http:\/\/bangla.salearningschool.com\/?p=10194"},"modified":"2015-08-01T09:16:54","modified_gmt":"2015-08-01T13:16:54","slug":"urlretriever2-java-illustrates-how-the-url-class-can-simplify-communication-to-an-http-server","status":"publish","type":"post","link":"http:\/\/bangla.sitestree.com\/?p=10194","title":{"rendered":"UrlRetriever2.java Illustrates how the URL class can simplify communication to an HTTP server."},"content":{"rendered":"<pre>UrlRetriever2.java\u00a0 Illustrates how the URL class can simplify communication to an HTTP server.\r\n\r\nimport java.net.*;\r\nimport java.io.*;\r\n\r\n\/** Read a remote file using the standard URL class\r\n\u00a0*\u00a0 instead of connecting explicitly to the HTTP server.\r\n\u00a0*\r\n\u00a0*\u00a0 Taken from Core Web Programming from\r\n\u00a0*\u00a0 Prentice Hall and Sun Microsystems Press,\r\n\u00a0*\u00a0 .\r\n\u00a0*\u00a0 \u00a9 2001 Marty Hall and Larry Brown;\r\n\u00a0*\u00a0 may be freely used or adapted.\r\n\u00a0*\/\r\n\r\npublic class UrlRetriever2 {\r\n\u00a0 public static void main(String[] args) {\r\n\u00a0\u00a0\u00a0 checkUsage(args);\r\n\u00a0\u00a0\u00a0 try {\r\n\u00a0\u00a0\u00a0\u00a0\u00a0 URL url = new URL(args[0]);\r\n\u00a0\u00a0\u00a0\u00a0\u00a0 BufferedReader in = new BufferedReader(\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 new InputStreamReader(url.openStream()));\r\n\u00a0\u00a0\u00a0\u00a0\u00a0 String line;\r\n\u00a0\u00a0\u00a0\u00a0\u00a0 while ((line = in.readLine()) != null) {\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 System.out.println(\"&gt; \" + line);\r\n\u00a0\u00a0\u00a0\u00a0 }\r\n\u00a0\u00a0\u00a0\u00a0\u00a0 in.close();\r\n\u00a0\u00a0\u00a0 } catch(MalformedURLException mue) { \/\/ URL constructor\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 System.out.println(args[0] + \"is an invalid URL: \" + mue);\r\n\u00a0\u00a0\u00a0 } catch(IOException ioe) { \/\/ Stream constructors\r\n\u00a0\u00a0\u00a0\u00a0\u00a0 System.out.println(\"IOException: \" + ioe);\r\n\u00a0\u00a0\u00a0 }\r\n\u00a0 }\r\n\r\n\u00a0 private static void checkUsage(String[] args) {\r\n\u00a0\u00a0\u00a0 if (args.length != 1) {\r\n\u00a0\u00a0\u00a0\u00a0\u00a0 System.out.println(\"Usage: UrlRetriever2 \");\r\n\u00a0\u00a0\u00a0\u00a0\u00a0 System.exit(-1);\r\n\u00a0\u00a0\u00a0 }\r\n\u00a0 }\r\n}<\/pre>\n","protected":false},"excerpt":{"rendered":"<p>UrlRetriever2.java\u00a0 Illustrates how the URL class can simplify communication to an HTTP server. import java.net.*; import java.io.*; \/** Read a remote file using the standard URL class \u00a0*\u00a0 instead of connecting explicitly to the HTTP server. \u00a0* \u00a0*\u00a0 Taken from Core Web Programming from \u00a0*\u00a0 Prentice Hall and Sun Microsystems Press, \u00a0*\u00a0 . \u00a0*\u00a0 \u00a9 &hellip; <\/p>\n<p><a class=\"more-link btn\" href=\"http:\/\/bangla.sitestree.com\/?p=10194\">Continue reading<\/a><\/p>\n","protected":false},"author":130,"featured_media":0,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"_jetpack_memberships_contains_paid_content":false,"footnotes":""},"categories":[1417,1424],"tags":[706,308,285],"class_list":["post-10194","post","type-post","status-publish","format-standard","hentry","category-code-programming-samples--","category-javaj2eej2me","tag-code","tag-java","tag-285","item-wrap"],"jetpack_featured_media_url":"","jetpack_sharing_enabled":true,"jetpack-related-posts":[{"id":26593,"url":"http:\/\/bangla.sitestree.com\/?p=26593","url_meta":{"origin":10194,"position":0},"title":"UrlRetriever2.java  Illustrates how the URL class can simplify communication to an HTTP server. #Programming Code Examples #Java\/J2EE\/J2ME #Network Programming","author":"Author-Check- Article-or-Video","date":"April 29, 2021","format":false,"excerpt":"UrlRetriever2.java Illustrates how the URL class can simplify communication to an HTTP server. import java.net.*; import java.io.*; \/** Read a remote file using the standard URL class * instead of connecting explicitly to the HTTP server. * * Taken from Core Web Programming from * Prentice Hall and Sun Microsystems\u2026","rel":"","context":"In &quot;FromSitesTree.com&quot;","block_context":{"text":"FromSitesTree.com","link":"http:\/\/bangla.sitestree.com\/?cat=1917"},"img":{"alt_text":"","src":"","width":0,"height":0},"classes":[]},{"id":10192,"url":"http:\/\/bangla.sitestree.com\/?p=10192","url_meta":{"origin":10194,"position":1},"title":"UrlRetriever.java Accepts an URL from the command line, parses the host, port, and URI components from the URL and then retrieves the document. Requires the following classes","author":"","date":"August 24, 2015","format":false,"excerpt":"UrlRetriever.java\u00a0 Accepts an URL from the command line, parses the host, port, and URI components from the URL and then retrieves the document. Requires the following classes: import java.util.*; \/** This parses the input to get a host, port, and file, then \u00a0*\u00a0 passes these three values to the UriRetriever\u2026","rel":"","context":"In &quot;Code . Programming Samples . \u09aa\u09cd\u09b0\u09cb\u0997\u09cd\u09b0\u09be\u09ae \u0989\u09a6\u09be\u09b9\u09b0\u09a8&quot;","block_context":{"text":"Code . Programming Samples . \u09aa\u09cd\u09b0\u09cb\u0997\u09cd\u09b0\u09be\u09ae \u0989\u09a6\u09be\u09b9\u09b0\u09a8","link":"http:\/\/bangla.sitestree.com\/?cat=1417"},"img":{"alt_text":"","src":"","width":0,"height":0},"classes":[]},{"id":26591,"url":"http:\/\/bangla.sitestree.com\/?p=26591","url_meta":{"origin":10194,"position":2},"title":"UrlRetriever.java  Accepts an URL from the command line, parses the host, port, and URI components from the URL and then retrieves the document. Requires the following classes: #Programming Code Examples #Java\/J2EE\/J2ME #Network Programming","author":"Author-Check- Article-or-Video","date":"April 29, 2021","format":false,"excerpt":"UrlRetriever.java Accepts an URL from the command line, parses the host, port, and URI components from the URL and then retrieves the document. Requires the following classes: import java.util.*; \/** This parses the input to get a host, port, and file, then * passes these three values to the UriRetriever\u2026","rel":"","context":"In &quot;FromSitesTree.com&quot;","block_context":{"text":"FromSitesTree.com","link":"http:\/\/bangla.sitestree.com\/?cat=1917"},"img":{"alt_text":"","src":"","width":0,"height":0},"classes":[]},{"id":26489,"url":"http:\/\/bangla.sitestree.com\/?p=26489","url_meta":{"origin":10194,"position":3},"title":"UriRetriever.java  Accepts a host, port, and file from the command line and retrieves the implied URL from the HTTP server by issuing a GET request. Uses the following classes: #Programming Code Examples #NULL #Network Programming","author":"Author-Check- Article-or-Video","date":"April 26, 2021","format":false,"excerpt":"UriRetriever.java Accepts a host, port, and file from the command line and retrieves the implied URL from the HTTP server by issuing a GET request. Uses the following classes: import java.net.*; import java.io.*; \/** Retrieve a URL given the host, port, and file as three * separate command-line arguments. A\u2026","rel":"","context":"In &quot;FromSitesTree.com&quot;","block_context":{"text":"FromSitesTree.com","link":"http:\/\/bangla.sitestree.com\/?cat=1917"},"img":{"alt_text":"","src":"","width":0,"height":0},"classes":[]},{"id":10183,"url":"http:\/\/bangla.sitestree.com\/?p=10183","url_meta":{"origin":10194,"position":4},"title":"NetworkClientTest.java Makes a simple connection to the host and port specified on the command line. Uses the following classes","author":"","date":"August 21, 2015","format":false,"excerpt":"NetworkClientTest.java\u00a0 Makes a simple connection to the host and port specified on the command line. Uses the following classes: \/** Make simple connection to host and port specified. \u00a0* \u00a0*\u00a0 Taken from Core Web Programming from \u00a0*\u00a0 Prentice Hall and Sun Microsystems Press, \u00a0*\u00a0 . \u00a0*\u00a0 \u00a9 2001 Marty Hall\u2026","rel":"","context":"In &quot;Code . Programming Samples . \u09aa\u09cd\u09b0\u09cb\u0997\u09cd\u09b0\u09be\u09ae \u0989\u09a6\u09be\u09b9\u09b0\u09a8&quot;","block_context":{"text":"Code . Programming Samples . \u09aa\u09cd\u09b0\u09cb\u0997\u09cd\u09b0\u09be\u09ae \u0989\u09a6\u09be\u09b9\u09b0\u09a8","link":"http:\/\/bangla.sitestree.com\/?cat=1417"},"img":{"alt_text":"","src":"","width":0,"height":0},"classes":[]},{"id":26583,"url":"http:\/\/bangla.sitestree.com\/?p=26583","url_meta":{"origin":10194,"position":5},"title":"NetworkClientTest.java  Makes a simple connection to the host and port specified on the command line. Uses the following classes: #Programming Code Examples #Java\/J2EE\/J2ME #Network Programming","author":"Author-Check- Article-or-Video","date":"April 29, 2021","format":false,"excerpt":"NetworkClientTest.java Makes a simple connection to the host and port specified on the command line. Uses the following classes: \/** Make simple connection to host and port specified. * * Taken from Core Web Programming from * Prentice Hall and Sun Microsystems Press, * . * \u00a9 2001 Marty Hall\u2026","rel":"","context":"In &quot;FromSitesTree.com&quot;","block_context":{"text":"FromSitesTree.com","link":"http:\/\/bangla.sitestree.com\/?cat=1917"},"img":{"alt_text":"","src":"","width":0,"height":0},"classes":[]}],"_links":{"self":[{"href":"http:\/\/bangla.sitestree.com\/index.php?rest_route=\/wp\/v2\/posts\/10194","targetHints":{"allow":["GET"]}}],"collection":[{"href":"http:\/\/bangla.sitestree.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/bangla.sitestree.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/bangla.sitestree.com\/index.php?rest_route=\/wp\/v2\/users\/130"}],"replies":[{"embeddable":true,"href":"http:\/\/bangla.sitestree.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=10194"}],"version-history":[{"count":1,"href":"http:\/\/bangla.sitestree.com\/index.php?rest_route=\/wp\/v2\/posts\/10194\/revisions"}],"predecessor-version":[{"id":10195,"href":"http:\/\/bangla.sitestree.com\/index.php?rest_route=\/wp\/v2\/posts\/10194\/revisions\/10195"}],"wp:attachment":[{"href":"http:\/\/bangla.sitestree.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=10194"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/bangla.sitestree.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=10194"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/bangla.sitestree.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=10194"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}