{"id":143,"date":"2007-04-12T15:33:04","date_gmt":"2007-04-12T06:33:04","guid":{"rendered":"https:\/\/deskplate.net\/blog\/2007\/04\/12\/java%e3%81%a7%e3%81%aehttp%e3%82%af%e3%83%a9%e3%82%a4%e3%82%a2%e3%83%b3%e3%83%88\/"},"modified":"2007-04-12T15:33:04","modified_gmt":"2007-04-12T06:33:04","slug":"java%e3%81%a7%e3%81%aehttp%e3%82%af%e3%83%a9%e3%82%a4%e3%82%a2%e3%83%b3%e3%83%88","status":"publish","type":"post","link":"https:\/\/deskplate.net\/blog\/archives\/143","title":{"rendered":"Java\u3067\u306eHTTP\u30af\u30e9\u30a4\u30a2\u30f3\u30c8"},"content":{"rendered":"<p>Applet\u5185\u90e8\u30c7\u30d0\u30c3\u30b0\u3067\u4f7f\u3063\u3066\u3044\u307e\u3059\u3002<br \/>\nApplet\u304b\u3089\u306e\u30ed\u30b0\u51fa\u529b\u306f\u3067\u304d\u306a\u3044\u3063\u307d\u3044\u306e\u3067CGI\u306b\u5024\u3092\u6e21\u3057\u3066\u30ed\u30b0\u3092\u51fa\u3057\u3066\u3044\u307e\u3059\u3002<br \/>\nGet\u30e1\u30bd\u30c3\u30c9\u306e\u5834\u5408<br \/>\n\u3000\u3000public void debug( String str ){<br \/>\n\u3000\u3000\u3000\u3000\u3000\u3000String _str = str;<br \/>\n\u3000\u3000\u3000\u3000\u3000\u3000String debug_url = &#8220;http:\/\/\u30c7\u30d0\u30c3\u30b0\u7528CGI\u306eURL?str=&#8221;;<br \/>\n\u3000\u3000\u3000\u3000\u3000\u3000<br \/>\n\u3000\u3000\u3000\u3000\u3000\u3000try {<br \/>\n\u3000\u3000\u3000\u3000\u3000\u3000\u3000\u3000URL _url = new URL( debug_url + _str );<br \/>\n\u3000\u3000\u3000\u3000\u3000\u3000\u3000\u3000HttpURLConnection urlconn = (HttpURLConnection)_url.openConnection();<br \/>\n\u3000\u3000\u3000\u3000\u3000\u3000\u3000\u3000urlconn.setRequestMethod(&#8220;GET&#8221;);<br \/>\n\u3000\u3000\u3000\u3000\u3000\u3000\u3000\u3000urlconn.setInstanceFollowRedirects(false);<br \/>\n\u3000\u3000\u3000\u3000\u3000\u3000\u3000\u3000urlconn.setRequestProperty(&#8220;Accept-Language&#8221;, &#8220;ja;q=0.7,en;q=0.3&#8221;);<br \/>\n\u3000\u3000\u3000\u3000\u3000\u3000\u3000\u3000urlconn.connect();<br \/>\n\u3000\u3000\u3000\u3000    \u3000\u3000<br \/>\n\u3000\u3000\u3000\u3000\u3000\u3000\u3000\u3000BufferedReader reader = new BufferedReader(new InputStreamReader(urlconn.getInputStream()));<br \/>\n\u3000\u3000\u3000\u3000\u3000\u3000\u3000\u3000while (true){<br \/>\n\u3000\u3000\u3000\u3000\u3000\u3000\u3000\u3000\u3000\u3000String line = reader.readLine();<br \/>\n\u3000\u3000\u3000\u3000\u3000\u3000\u3000\u3000\u3000\u3000if ( line == null ){<br \/>\n\u3000\u3000\u3000\u3000\u3000\u3000\u3000\u3000\u3000\u3000\u3000\u3000\u3000\u3000break;<br \/>\n\u3000\u3000\u3000\u3000\u3000\u3000\u3000\u3000\u3000\u3000}<br \/>\n\u3000\u3000\u3000\u3000\u3000\u3000\u3000\u3000}<br \/>\n\u3000\u3000<br \/>\n\u3000\u3000\u3000\u3000\u3000\u3000\u3000\u3000reader.close();<br \/>\n\u3000\u3000\u3000\u3000    \u3000\u3000<br \/>\n\u3000\u3000\u3000\u3000\u3000\u3000\u3000\u3000urlconn.disconnect();<br \/>\n\u3000\u3000\u3000\u3000\u3000\u3000\u3000\u3000<br \/>\n\u3000\u3000\u3000\u3000\u3000\u3000}<br \/>\n\u3000\u3000\u3000\u3000\u3000\u3000catch(Throwable e){<br \/>\n\u3000\u3000\u3000\u3000<br \/>\n\u3000\u3000\u3000\u3000\u3000\u3000}finally{<br \/>\n\u3000\u3000\u3000\u3000\u3000\u3000\u3000\u3000try{<br \/>\n\u3000\u3000\u3000\u3000\u3000\u3000\u3000\u3000}catch(Exception e){}<br \/>\n\u3000\u3000\u3000\u3000\u3000\u3000}<br \/>\n\u3000\u3000\u3000\u3000<br \/>\n\u3000\u3000}<br \/>\nPost\u30e1\u30bd\u30c3\u30c9\u306e\u5834\u5408<br \/>\n\u3000\u3000public void debug( String str ){<br \/>\n\u3000\u3000\u3000\u3000\u3000\u3000String _str = str;<br \/>\n\u3000\u3000\u3000\u3000\u3000\u3000String debug_url = &#8220;http:\/\/\u30c7\u30d0\u30c3\u30b0\u7528CGI\u306eURL?str=&#8221;;<br \/>\n\u3000\u3000\u3000\u3000\u3000\u3000try{<br \/>\n\u3000\u3000\u3000\u3000\u3000\u3000\u3000\u3000URL _url = new URL( debug_url  );<br \/>\n\u3000\u3000\u3000\u3000\u3000\u3000\u3000\u3000HttpURLConnection conn = (HttpURLConnection)_url.openConnection();<br \/>\n\u3000\u3000\u3000\u3000\u3000\u3000\u3000\u3000<br \/>\n\u3000\u3000\u3000\u3000\u3000\u3000\u3000\u3000conn.setUseCaches(false);<br \/>\n\u3000\u3000\u3000\u3000\u3000\u3000\u3000\u3000conn.setRequestMethod(&#8220;POST&#8221;); \/* GET or POST *\/<br \/>\n\u3000\u3000\u3000\u3000\u3000\u3000\u3000\u3000conn.setDoOutput(true); \/* GET:false \/ POST:true *\/<br \/>\n\u3000\u3000\u3000\u3000\u3000\u3000\u3000\u3000conn.connect();<br \/>\n\u3000\u3000\u3000\u3000\u3000\u3000\u3000\u3000<br \/>\n\u3000\u3000\u3000\u3000\u3000\u3000\u3000\u3000BufferedWriter writer = new BufferedWriter(new OutputStreamWriter(conn.getOutputStream()));<br \/>\n\u3000\u3000\u3000\u3000\u3000\u3000\u3000\u3000StringBuffer outBuf = new StringBuffer();<br \/>\n\u3000\u3000\u3000\u3000\u3000\u3000\u3000\u3000\/* GET \u306e\u5834\u5408\u306f URL \u306b\u304f\u3063\u3064\u3051\u308b\u3002 *\/<br \/>\n\u3000\u3000\u3000\u3000\u3000\u3000\u3000\u3000outBuf.append(&#8220;&#038;str=&#8221;).append(URLEncoder.encode(_str,&#8221;UTF-8&#8243;));<br \/>\n\u3000\u3000\u3000\u3000\u3000\u3000\u3000\u3000writer.write(outBuf.toString());<br \/>\n\u3000\u3000\u3000\u3000\u3000\u3000\u3000\u3000writer.close();<br \/>\n\u3000\u3000\u3000\u3000\u3000\u3000\u3000\u3000BufferedReader reader = new BufferedReader(new InputStreamReader(conn.getInputStream(),&#8221;UTF-8&#8243;));<br \/>\n\u3000\u3000\u3000\u3000\u3000\u3000\u3000\u3000StringBuffer inBuf = new StringBuffer();<br \/>\n\u3000\u3000\u3000\u3000\u3000\u3000\u3000\u3000String line;<br \/>\n\u3000\u3000\u3000\u3000\u3000\u3000\u3000\u3000<br \/>\n\u3000\u3000\u3000\u3000\u3000\u3000\u3000\u3000while((line = reader.readLine()) != null){<br \/>\n\u3000\u3000\u3000\u3000\u3000\u3000\u3000\u3000\u3000\u3000inBuf.append(line).append(&#8216;\\n&#8217;);<br \/>\n\u3000\u3000\u3000\u3000\u3000\u3000\u3000\u3000}<br \/>\n\u3000\u3000\u3000\u3000\u3000\u3000\u3000\u3000<br \/>\n\u3000\u3000\u3000\u3000\u3000\u3000\u3000\u3000System.out.println(inBuf.toString());<br \/>\n\u3000\u3000\u3000\u3000\u3000\u3000\u3000\u3000reader.close();<br \/>\n\u3000\u3000\u3000\u3000\u3000\u3000\u3000\u3000conn.disconnect();<br \/>\n\u3000\u3000\u3000\u3000\u3000\u3000\u3000\u3000<br \/>\n\u3000\u3000\u3000\u3000\u3000\u3000}catch(Exception ex){<br \/>\n\u3000\u3000\u3000\u3000\u3000\u3000\u3000\u3000ex.printStackTrace();<br \/>\n\u3000\u3000\u3000\u3000\u3000\u3000}<br \/>\n\u3000\u3000}<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Applet\u5185\u90e8\u30c7\u30d0\u30c3\u30b0\u3067\u4f7f\u3063\u3066\u3044\u307e\u3059\u3002<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[4],"tags":[],"class_list":["post-143","post","type-post","status-publish","format-standard","hentry","category-java"],"_links":{"self":[{"href":"https:\/\/deskplate.net\/blog\/wp-json\/wp\/v2\/posts\/143","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/deskplate.net\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/deskplate.net\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/deskplate.net\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/deskplate.net\/blog\/wp-json\/wp\/v2\/comments?post=143"}],"version-history":[{"count":0,"href":"https:\/\/deskplate.net\/blog\/wp-json\/wp\/v2\/posts\/143\/revisions"}],"wp:attachment":[{"href":"https:\/\/deskplate.net\/blog\/wp-json\/wp\/v2\/media?parent=143"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/deskplate.net\/blog\/wp-json\/wp\/v2\/categories?post=143"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/deskplate.net\/blog\/wp-json\/wp\/v2\/tags?post=143"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}