我试图通过发出 HTTP 请求来更新 Android 中的 MySQL 数据,但它给了我一个错误
“类型不匹配:无法从 org.apache.http.HttpResponse 转换为 com.google.api.client.http.HttpResponse”
在这行代码“httpClient.execute(httpPost)”
HttpResponse response = httpClient.execute(httpPost);
它提供了通过添加 org.apache.http 来快速修复的选项
org.apache.http.HttpResponse response = httpClient.execute(httpPost);
有人可以告诉我我在这里做错了什么吗?非常感谢!
protected String doInBackground(String... params) {
HttpClient httpClient = new DefaultHttpClient();
HttpPost httpPost = new HttpPost("http://---.com/---/approve_request.php");
List<NameValuePair> nameValuePair = new ArrayList<NameValuePair>();
nameValuePair.add(new BasicNameValuePair("status", "Approved"));
try {
httpPost.setEntity(new UrlEncodedFormEntity(nameValuePair));
} catch (UnsupportedEncodingException e) {
e.printStackTrace();
}
try {
org.apache.http.HttpResponse response = httpClient.execute(httpPost);
Log.d("Http Response:", response.toString());
} catch (ClientProtocolException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
return null;
}
最佳答案
您的代码中有错误的导入语句。
转到类(class)顶部并查找
导入 com.google.api.client.http.HttpResponse
替换为
import org.apache.http.HttpResponse
关于java - 类型不匹配 : cannot convert from org. apache.http.HttpResponse,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13183111/