我在找工作HtttpRequest
類,這樣我可以做這樣的:Android平臺HttpRequest類
String response = Request.get("http://google.com");
我已經寫了一個類,但它不Android 3+
工作,但在2.3確實。
public class WebRequest {
public String get(String url){
HttpClient httpclient = new DefaultHttpClient();
try {
HttpGet httpget = new HttpGet(url);
// Create a response handler
ResponseHandler<String> responseHandler = new BasicResponseHandler();
String responseBody = httpclient.execute(httpget, responseHandler);
return responseBody;
} catch (ClientProtocolException e) {
e.printStackTrace();
return null;
} catch (IOException e) {
e.printStackTrace();
return null;
} finally {
// When HttpClient instance is no longer needed,
// shut down the connection manager to ensure
// immediate deallocation of all system resources
httpclient.getConnectionManager().shutdown();
}
}
請幫助!
是在2.3的工作?如果是這樣檢查錯誤是嚴格模式策略,如果這樣將其轉換爲異步任務 – 2013-03-25 12:23:07
它可能與編碼有關,嘗試將它傳遞給UTF-8編碼的URL – meh 2013-03-25 12:24:08
請顯示代碼,這是行不通的。 – 2013-03-25 12:27:47