最大内容长度?

我正在尝试使用HttpURLConnection连接服务器,但我的PUT方法有问题。
我需要发送一个包含1500个字符 (或更多)的字符串,但在这种情况下,服务器会产生超时并返回500 – 服务器内部错误
如果我发送一个低于1400个字符的字符串,我没有问题,服务器返回OK

我的代码如下:

 public String connectToServer(String prototype) { String responseString = ""; try { BufferedReader in = new BufferedReader(new InputStreamReader(openURLForInput(new URL(URL), USERNAME, PASSWORD, prototype))); String line; while ((line = in.readLine()) != null) { System.out.println(line); responseString += line; } } catch (IOException e) { e.printStackTrace(); responseString = e.toString(); } return responseString; } 

// ———————–

 public InputStream openURLForInput(URL url, String uname, String pword, String content) throws IOException { HttpURLConnection conn = (HttpURLConnection) url.openConnection(); conn.setDoInput(true); conn.setDoOutput(true); conn.setRequestProperty("Authorization", userNamePasswordBase64(uname, pword)); // I know this is OK conn.addRequestProperty("Content-type", "application/xml; charset=utf-8"); //conn.setChunkedStreamingMode(8 * 1024); conn.setRequestMethod("PUT"); conn.connect(); OutputStream output = conn.getOutputStream(); OutputStreamWriter osw = new OutputStreamWriter(output, "UTF-8"); BufferedWriter writer = new BufferedWriter(osw); writer.write(content); // content length > 1400 characters writer.close(); output.close(); int status = conn.getResponseCode(); Log.i("STATUS", status + ""); Log.i("STATUS_ERROR", conn.getResponseMessage()); return conn.getInputStream(); } 

我尝试添加线条

 conn.setFixedLengthStreamingMode(contentLength) conn.setChunkedStreamingMode(8 * 1024); 

但无论如何,服务器的答案是错误的。

更新:

我可以发现问题。 出于某种原因,当我尝试在请求中发送大型机身时,服务器会产生超时但不是所有网络 ,只有一些网络。 我使用安全连接SSL,这可能会带来问题吗?

也许这是一个网络MTU问题,我会说你在这方面进行调查。

这是一个与windows相关的表:

 Network MTU (bytes) ------------------------------- 16 Mbps Token Ring 17914 4 Mbps Token Ring 4464 FDDI 4352 Ethernet 1500 IEEE 802.3/802.2 1492 PPPoE (WAN Miniport) 1480 X.25 576 

我建议你使用Kevin Sawicki非常有用的HTTP-REQUEST库…

它帮助了我很多次!

服务器正在响应500 – 服务器内部错误。 所以你应该检查服务器实现。 它应该具有高于该内容长度的限制。
我有一个应用程序,做了很多服务器http请求,对我来说,你的问题确实是服务器。 主要证据是您的代码使用的内容低于或等于1415个字符。