{"id":2183,"date":"2022-08-30T15:22:44","date_gmt":"2022-08-30T15:22:44","guid":{"rendered":"https:\/\/unknownerror.org\/index.php\/2014\/01\/04\/restful-request-using-httpurlconnection-collection-of-common-programming-errors\/"},"modified":"2022-08-30T15:22:44","modified_gmt":"2022-08-30T15:22:44","slug":"restful-request-using-httpurlconnection-collection-of-common-programming-errors","status":"publish","type":"post","link":"https:\/\/unknownerror.org\/index.php\/2022\/08\/30\/restful-request-using-httpurlconnection-collection-of-common-programming-errors\/","title":{"rendered":"RESTful request using HTTPUrlConnection-Collection of common programming errors"},"content":{"rendered":"<p>I&#8217;m writing my first Android app, and trying to get the hang of making a REST call from within the app. Following a couple pages and other SO posts, I&#8217;ve got this:<\/p>\n<pre><code>URL serverUrl = new URL(\"http:\/\/localhost:13980\/api\/maps\/\"); \/\/the value is hardcoded for testing purposes\n\npublic String getMapsJson()\n{\n    Log.d(\"Minimap\", \"&gt;&gt; getting maps json from \" + serverUrl.toString());\n    String output = \"\";\n\n    HttpURLConnection connection = null;\n\n    try\n    {\n        connection = (HttpURLConnection) serverUrl.openConnection();\n        connection.setRequestMethod(\"GET\");\n        Log.d(\"Minimap\", \"connection opened!\");\n        InputStream in = new BufferedInputStream(connection.getInputStream());\n        Log.d(\"Minimap\", \"input stream captured\");\n        output = readStream(in);\n        Log.d(\"Minimap\", \"stream read\");\n    }\n\n    catch (Exception e)\n    {\n        Log.d(\"Minimap\", e.getMessage()); \/\/************* This is line 53<\/code><\/pre>\n<p id=\"rop\"><small>Originally posted 2014-01-04 02:52:06. <\/small><\/p>","protected":false},"excerpt":{"rendered":"<p>I&#8217;m writing my first Android app, and trying to get the hang of making a REST call from within the app. Following a couple pages and other SO posts, I&#8217;ve got this: URL serverUrl = new URL(&#8220;http:\/\/localhost:13980\/api\/maps\/&#8221;); \/\/the value is hardcoded for testing purposes public String getMapsJson() { Log.d(&#8220;Minimap&#8221;, &#8220;&gt;&gt; getting maps json from &#8221; [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1],"tags":[],"class_list":["post-2183","post","type-post","status-publish","format-standard","hentry","category-uncategorized"],"_links":{"self":[{"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/posts\/2183","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/comments?post=2183"}],"version-history":[{"count":0,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/posts\/2183\/revisions"}],"wp:attachment":[{"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/media?parent=2183"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/categories?post=2183"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/tags?post=2183"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}