When I use android DefaultHttpClient http request this class do encounter a problem when I set
httpget.setHeader ("User-Agent", UA);
UA is "" When can request data, when UA UA is true no data on the request, did not report any abnormalities, such as blocking of the same without any response
You have encountered this situation seek solutions
Note: Do not know about the network settings
Address test is: http://www.baidu.com
Code is as follows:
httpUrl = "http://www.baidu.com";
InputStream is = null;
DefaultHttpClient httpClient = new DefaultHttpClient ();
HttpGet httpget = new HttpGet (httpUrl);
/ / Request timeout
httpget.getParams () setParameter (CoreConnectionPNames.CONNECTION_TIMEOUT, 20000);.
httpget.setHeader ("Connection", "close");
httpget.setHeader ("User-Agent", UA);
HttpResponse response = httpClient.execute (httpget);
if (response.getStatusLine (). getStatusCode () == HttpStatus.SC_OK) {
HttpEntity entity = response.getEntity ();
if (null! = entity) {
is = entity.getContent ();
String rs = convertStreamToString (is);
Message msg = mHandler.obtainMessage ();
msg.obj = rs;
mHandler.sendMessage (msg);
}
}
<-! Main posts under Banner (D4) -><-! Posts under the main text (D5) ->
Reply:
Nobody met you, I do not know how to set up the network needs ah
No comments:
Post a Comment