سؤال

i simply to understand how but this are the fact

httpClient = new DefaultHttpClient();

work fine .

but this :

HttpParams httpParameters = new BasicHttpParams();
httpClient = new DefaultHttpClient(httpParameters);

returned server error (400)

how could it be ? i didn't changed anything but adding empty params ....

i also check the fields of the httpClient and i didnt saw anything diffrent

Before

After

هل كانت مفيدة؟

المحلول

The HttpParams values that are included in a new DefaultHttpClient contain some basic headers (like user agent and protocol version), while a brand new BasicHttpParams is completely empty.

http.protocol.expect-continue=false, 
http.protocol.version=HTTP/1.1, 
http.protocol.content-charset=ISO-8859-1, 
http.useragent=Apache-HttpClient/UNAVAILABLE (java 1.4)

Your server is probably expecting at least some of them, hence the "bad request" response.

If you need to add custom parameters, you should start with httpClient.getParams() and build them from there.

مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top