対象範囲: Androidに含まれているhttp apacheライブラリを使用しており、HttpPostをHttpClient経由でHttpEntityで実行しようとしています(ContentProducerでEntityTemplateから作成)。EntityTemplateのコンテンツ長がnullの場合
HttpClient httpClient = new CustomHttpsClient().getNewHttpClient();
HttpPost httpPost = new HttpPost("APP_URI");
HttpEntity postEntity;
HttpEntity getEntity;
ContentProducer contentProducer = new ContentProducer() {
@Override
public void writeTo(OutputStream outstream) throws IOException {
// TODO Auto-generated method stub
Writer writer = new OutputStreamWriter(outstream, "UTF-8");
writer.write("<req version=\"1.0\" lang=\"RU\">");
writer.write("<act>o_addcard</act>");
writer.write("</req>");
writer.flush();
}
};
postEntity = new EntityTemplate(contentProducer);
httpPost.setEntity(postEntity);
String responseEntity;
try {
HttpResponse httpResponse = httpClient.execute(httpPost);
...} catch(...){...}
問題:: Serverは常に(コンテンツ長がnullである)私に411応答コードを示します:
"POST/HTTP/1.1" 411 180 "ここ はコードです - "" - "
これらのコードは一部のサーバーで動作します。しかし、なぜコンテンツの長さが常にnullですか? また、我々は、我々はによって引き起こされる例外持っているそれ以外の場合は、手動で設定することはできません。
によって引き起こさ:org.apache.http.ProtocolException:あなたのためのContent-Lengthヘッダが既に存在
感謝を答え!
www.google.comのようないくつかの標準的なサーバーにアクセスし、あなたのコードが正しい場合は出力としていくつかのHTMLテキストを取得する必要があります。 – Naresh
Google.comは私に405を与えます(とにかく投稿を拒否するので、コンテンツ長のチェックには使用できません)。私は別のサーバーを試しました、彼らはすべて私に411を与える。ありがとう、それはアイデアだった!しかし、まだ幸運... –
あなたはHttpPostの代わりにHTTpGetメソッドを使用する必要があります – Naresh