私のJavaコードから複数のフォームデータを送信しようとしています。誰かが次のようにContent Lengthを設定する方法を教えてもらえますか? ContentDescriptorインターフェイスを実装するInputStreamBodyを使用すると、ヘッダーが含まれているようです。 InputStreamBodyでgetContentLengthを実行すると、コンテンツを追加した後に私に-1が与えられます。 contentLengthにはバイト配列の長さを与えるためにサブクラス化しましたが、ContentDescriptorに必要な他のヘッダーが適切なPOSTに設定されているかどうかはわかりません。ContentStreamのHttpMime 4.0.3設定のInputStreamBody
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();
こんにちは、ありがとうございました。クラスを使用しているときに次のエラーが発生しています... httpmimeとhttpclientの両方が4.1-beta1でなければなりませんか?それは私があなたの提案の後に持っている現在の設定です...
java.lang.AbstractMethodError at org.apache.http.entity.mime.HttpMultipart.doWriteTo(HttpMultipart.java:169) at org.apache.http.entity.mime.HttpMultipart.writeTo(HttpMultipart.java:191) at org.apache.http.entity.mime.MultipartEntity.writeTo(MultipartEntity.java:180) \t at org.apache.http.impl.entity.EntitySerializer.serialize(EntitySerializer.java:97)
– Ramこんにちは、私はどのようにマルチパートメッセージのためのContent-Encodingを設定するのですか?私はエンコーディングを問い合わせるときにnullになっています。どんな助けもありがとうございます。 – Ram
はい、両方とも4.1-beta1である必要があります –