Java http post: values arent added

I try to send post request, but webserver returns that I added no post-values. I spent a lot of time trying to solve this issue, but no result. Here is the code: public static String post(String url, String postParams) { URLConnection connection = null; try { connection = initializeConnection(url); connection.setDoOutput(true); ((HttpURLConnection) connection).setRequestMethod("POST"); connection.setRequestProperty("Content-Type", "text/xml"); connection.setRequestProperty("Accept", "text/xml"); connection.setUseCaches(false); connection.setDoInput(true); DataOutputStream wr = new DataOutputStream(connection.getOutputStream()); wr.write(postParams.getBytes()); wr.flush(); wr.close(); // Get Response InputStream is = connection.getInputStream(); return inputStreamToString(is); } catch (Exception e) { e.printStackTrace(); return null; } } protected static HttpURLConnection initializeConnection(String stringUrl) { HttpURLConnection connection; URL url = null; try { url = new URL(stringUrl); } catch (MalformedURLException e1) { e1.printStackTrace(); } try { connection = (HttpURLConnection) url.openConnection(); connection.setConnectTimeout(5000); } catch (Exception e) { e.printStackTrace(); return null; } return connection; } public static String inputStreamToString(InputStream is) { BufferedReader r = new BufferedReader(new InputStreamReader(is)); StringBuilder total = new StringBuilder(); String line; try { while ((line = r.readLine()) != null) { total.append(line); } } catch (IOException e) { e.printStackTrace(); } return total.toString(); } I receive a message from webserver where it is told that no post-values are added. As far as I understand from the code, the values are added. I'm stuck.
use Wireshark or Fiddler to check the data transmission on the network layer.

以上就是Java http post: values arent added的详细内容,更多请关注web前端其它相关文章!

赞(0) 打赏
未经允许不得转载:web前端首页 » JavaScript 答疑

评论 抢沙发

  • 昵称 (必填)
  • 邮箱 (必填)
  • 网址

前端开发相关广告投放 更专业 更精准