获取java.io.IOException:在getInputStream上写入服务器时出错 [英] Getting java.io.IOException: Error writing to server at getInputStream
问题描述
如果临时字符串很大,我将得到java.io.IOException:在getInputStream上写入服务器时出错
If the temp string is very large I get java.io.IOException: Error writing to server at getInputStream
String tmp = js.deepSerialize(taskEx);
URL url = new URL("http://"
+ "localhost"
+ ":"
+ "8080"
+ "/Myproject/TestServletUpdated?command=startTask&taskeId=" +taskId + "'&jsonInput={\"result\":"
+ URLEncoder.encode(tmp) + "}");
URLConnection conn = url.openConnection();
InputStream is = conn.getInputStream();
那是为什么? 该调用转到URL中提到的servlet.
Why is that? This call goes to the servlet mentioned in the URL.
推荐答案
I think you might have a "too long url", the maximum number of characters are 2000 (see this SO post for more info). GET requests are not made to handle such long data input.
如果您还可以更改servlet代码,则可以将其更改为POST而不是GET请求(如您现在的要求).客户端代码看起来很像:
You can, if you can change the servlet code also, change it into a POST instead of a GET request (as you have today). The client code would look pretty simular:
public static void main(String[] args) throws IOException {
URL url = new URL("http", "localhost:8080", "/Myproject/TestServletUpdated");
URLConnection conn = url.openConnection();
conn.setDoOutput(true);
OutputStreamWriter wr = new OutputStreamWriter(conn.getOutputStream());
wr.write("command=startTask" +
"&taskeId=" +taskId +
"&jsonInput={\"result\":" + URLEncoder.encode(tmp) + "}");
wr.flush();
.... handle the answer ...
}
我没有首先看到它,但似乎您的请求字符串中只有一个引号字符.
I didn't see it first but it seems like you have a single quote character in your request string.
...sk&taskeId=" + taskId + "'&jso.....
^
尝试删除它,可能会对您有所帮助!
try removing it, it might help you!
这篇关于获取java.io.IOException:在getInputStream上写入服务器时出错的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!