小编tom*_*tom的帖子

JAVA Http POST请求UTF-8

我的J2EE应用程序能够从JSP页面接收POST请求,没问题.

但是如果我使用另一个java应用程序发送POST请求,则收到的参数不是UTF-8字符串.

这里有我的代码:

URL url = new URL("http://localhost:8080/ITUNLPWebInterface/SimpleApi");
HttpURLConnection cox = (HttpURLConnection) url.openConnection();

cox.setDoInput(true);
cox.setDoOutput(true);
cox.setRequestMethod("POST");
cox.setRequestProperty("Accept-Charset", "UTF-8");
cox.setRequestProperty("Content-Type", "application/x-www-form-urlencoded");
cox.setRequestProperty("charset", "UTF-8");

DataOutputStream dos = new DataOutputStream(cox.getOutputStream());
String query = "tool=ner&input=?a?a?a";
dos.writeBytes(query);
dos.close();
Run Code Online (Sandbox Code Playgroud)

难道我做错了什么?

感谢您的回复

java http utf-8

7
推荐指数
2
解决办法
4万
查看次数

标签 统计

http ×1

java ×1

utf-8 ×1