Ich versuche, einen Körper in x-www-form-urlencoded
an meine lokale Web-API zu senden. Ich kann GET
ohne Probleme machen. Hier ist, was ich tue:content-length in HttpURLConnection
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: Content-Length versprach 598 Bytes, erhielt aber 0
So bedeutet es, dass ich keine Daten bin das Senden in meinem POST
, wie kommt es?
Sie Ihre postdata wie con.getOutputStream müssen send() schreiben (postdata) – Mick