Java コードを介してマルチパートのフォームデータ ポストを送信しようとしています。次のコンテンツの長さを設定する方法を教えてもらえますか?? ContentDescriptor インターフェイスを実装する InputStreamBody を使用する場合、関連するヘッダーがあるようです。InputStreamBody で getContentLength を実行すると、コンテンツを追加した後に -1 が返されます。contentLength にバイト配列の長さを与えるようにサブクラス化しましたが、ContentDescriptor に必要な他のヘッダーが適切な POST に設定されるかどうかはわかりません。
HttpClient httpclient = new DefaultHttpClient();
HttpPost httpPost = new HttpPost(myURL);
ContentBody cb = new InputStreamBody(new ByteArrayInputStream(bytearray), myMimeType, filename);
//ContentBody cb = new ByteArrayBody(bytearray, myMimeType, filename);
MultipartEntity mpentity = new MultipartEntity(HttpMultipartMode.BROWSER_COMPATIBLE);
mpentity.addPart("key", new StringBody("SOME_KEY"));
mpentity.addPart("output", new StringBody("SOME_NAME"));
mpentity.addPart("content", cb);
httpPost.setEntity(mpentity);
HttpResponse response = httpclient.execute(httpPost);
HttpEntity resEntity = response.getEntity();