x-www-form-urlencoded
の本文を自分のローカルWeb APIに送信しようとしています。 GET
を問題なく作成できます。ここで私は何をすべきかです:HttpURLConnectionのcontent-length
String urlParameters = "user=User&label=GPU+Temp&file=src%2FDataSource0.txt&backgroundColor=rgb(255%2C255%2C255%2C0)&borderColor=rgb(255%2C255%2C255%2C0)&pointBorderColor=rgb(255%2C255%2C255%2C0)&pointHoverBackgroundColor=rgb(255%2C255%2C255%2C0)&pointHoverBorderColor=rgb(255%2C255%2C255%2C0)&min=0&max=100&stepSize=50";
byte[] postData = urlParameters.getBytes(Charset.forName("UTF-8"));
int postDataLength = postData.length;
String request = "http://192.168.1.30:6262/api/values";
URL url = new URL(request);
con = (HttpURLConnection) url.openConnection();
con.setDoOutput(true);
con.setInstanceFollowRedirects(false);
con.setRequestMethod("POST");
con.setRequestProperty("Content-Type", "application/x-www-form-urlencoded");
con.setRequestProperty("charset", "utf-8");
con.setRequestProperty("Content-Length", Integer.toString(postDataLength));
con.connect();
java.net.ProtocolException:コンテンツの長さが598のバイトを約束したが、0
を受けたので、それは私が私の中に任意のデータを送信していないよということを意味しますPOST
、どうですか?
書き込み(POSTデータ)私は思ったこと – Mick