我想将信息发送到服务器,但它只是Content-Length
看到的部分信息不正确。
我的代码:
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();
只发送了680个字节,但它应该是大约2000个字节。
命令:
System.out.println(con.getContentLength());
结果:
680
此命令未更改Content-Length
:
con.setRequestProperty(`Content-Length`, `2000`);