java - 类型不匹配 : cannot convert from org. apache.http.HttpResponse

标签 java android httprequest

我试图通过发出 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/

相关文章:

http - 构成 HTTP 请求(和响应)的字母是否采用 ASCII 格式?

java - Java中如何调用另一个项目中的函数

java - Webdriver Java : Using regular expressions - how to insert them?

java - 安卓+Java :File deletion error

android - java.io.IOException : No such file or directory (save image)

javascript - 获取跨域客户端请求页面内容

javascript - AngularJS promise 不会干净地退出

java - 如何更新 Vaadin 网格上的项目而不显式放置所有字段?

java - 使用 Jackson 将具有 HashMap 的对象序列化为 JSON 时出现映射异常

java - 在 Python 中使用 HTTPS 的示例 Apache Thrift 服务