我对HttpClient
对象实例有疑问。
使用DefaultHttpClient
(不建议使用)构造函数,我的应用程序可以运行,但是当我将其替换为HttpClientBuilder.create().build()
时,会崩溃。
这是代码:
public String sendRequest(String parameterValue, String ipAddress, String portNumber, String parameterName) throws URISyntaxException, IOException {
String serverResponse = "ERROR";
URI website = new URI("http://"+ipAddress+":"+portNumber+"/?"+parameterName+"="+parameterValue);
HttpClient client = HttpClientBuilder.create().build();
HttpGet request = new HttpGet(website);
HttpResponse response = client.execute(request);
InputStream content = null;
content = response.getEntity().getContent();
BufferedReader in = new BufferedReader(new InputStreamReader(
content
));
serverResponse = in.readLine();
// Close the connection
content.close();
return serverResponse;
}
这是android studio向我显示的错误:
AndroidRuntime:严重例外:AsyncTask#3