0

サーバーに情報を送信したいのですが、 によって表示される情報の一部にすぎず、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`);
4

0 に答える 0