Maximum content length?

I am trying to connect to the server using HttpURLConnection , but I have a problem with the PUT method.
I need to send a string with 1500 characters (or more), but in this case the server issues a timeout and returns 500 - an internal server error .
If I send a string less than 1400 characters, I have no problem and the server returns OK .

My code is as follows:

 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(); } 

I tried to add lines

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

However, the server response is incorrect.

UPDATE:

I could detect a problem. For some reason, when I try to send large bodys to a request, the server creates a timeout , but not with all networks , only with some networks. I use SSL secure SSL, maybe this can cause problems?

+4
source share
3 answers

Maybe this is a MTU network problem, I would say that you are researching on this front.

Here is the table related to 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 
+2
source

I recommend you use the very useful HTTP-REQUEST library of Kevin Savicki ...

It has helped me many times!

0
source

The server responds to a 500-server internal error. Therefore, you should check the server implementation. It must have limits above this content length.
I have an application that makes a lot of server HTTP requests, and for me your problem is actually a server. The main evidence is that your code works with content below or equal to 1415 characters.

0
source

Source: https://habr.com/ru/post/1469514/


All Articles