Quantcast
Channel: OKWAVE 閲覧数の多い質問(Java/253)【本日】
Viewing all articles
Browse latest Browse all 68675

JavaでPOSTでデータ送信時のボディについて

$
0
0
javaでHTTP通信をする際にメソッドをPOSTにしてボディにパラメータを設定する仕方がいまいちわかりません。 調べてみても、POSTはGETのようにURLに付加するのではなくボディ部に設定すればよいというのはわかったのですが。実際どういうソースで設定できるのか例が見つからなく困っています。 なんとなくの判断ですが、 message = "httpテスト"; URL url = new URL("http://~~~/xxx.html"); HttpURLConnection http = (HttpURLConnection)url.openConnection(); http.setRequestMethod("POST"); http.setDoOutput(true); http.setRequestProperty("Content-Type", "~~~"); http.setRequestProperty("Content-Length", Integer.toString(message.length())); ↓↓↓(1) BufferedWriter outer = new BufferedWriter(new OutputStreamWriter(http.getOutputStream())); outer.write(message); outer.flush(); outer.close(); ↑↑↑(1) http.connect(); 上記(1)の箇所でボディへの設定ができているのかなという判断をしているのですが、あっていますでしょうか?? よろしくお願いします。

Viewing all articles
Browse latest Browse all 68675

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>