0

I want to send information to the server, but it is only part of the information seen by the Content-Length is not correct.

My code:

private static String boundary = `BOUNDARY`;
private static String break = `\r\n`;

String url = `https://`;
URL uUrl= new URL(url);

HttpsURLConnection con = (HttpsURLConnection) uUrl.openConnection();

con.setDoOutput(true);
con.setDoInput (true);
con.setUseCaches(false); 

con.setRequestMethod(`POST`);
con.setRequestProperty(`Content-Type`, `multipart/mixed; boundary=` + boundary);


//boundary
boundary = `--BOUNDARY` + break +   `Content-Type: application/x-www-form-urlencoded` + break;
boundary = boundary + `Content-Length: ` + `XXXXX`.length();
boundary = boundary + break+ break;
boundary = boundary + `XXXXX` + break;

boundary = boundary + break;
boundary = boundary + `--BOUNDARY` + break+   `Content-Type: application/x-ups-binary` + break;
boundary = boundary + `Content-Length: ` + sContent.length() + break;
boundary = boundary + break;
boundary = boundary + sContent + break;

boundary = boundary + break;
boundary = boundary + `--BOUNDARY--`;

DataOutputStream body = new DataOutputStream(con.getOutputStream());

body .writeBytes(boundary);
body .flush();      
body .close();

There are only 680 bytes sent but it should be about 2000.

command:

System.out.println(con.getContentLength());

result:

680

This command has not changed the Content-Length:

con.setRequestProperty(`Content-Length`, `2000`);
vzamanillo
  • 9,905
  • 1
  • 36
  • 56
  • What sContent is? I think you are sending an incorrect value, you need send the length of the request data in bytes content.getBytes().length – vzamanillo Mar 07 '14 at 14:32
  • In sContent the content is to be sent. sContent.length().getBytes().length I have changed it, but it did not help. Of boundary = boundary + sContent + break; to boundary = boundary + sContent.getBytes() + break; did not work – user3392838 Mar 07 '14 at 14:45

0 Answers0