【问题标题】:unable to get a response from http server无法从 http 服务器获得响应
【发布时间】:2011-07-14 14:44:07
【问题描述】:

我正在尝试通过使用 post 方法发送用户名和密码来向 url 发布帖子。但答案尚不清楚。

这是我的做法:

HttpClient httpclient =new DefaultHttpClient();

        HttpPost  httppost=new HttpPost("http://test.res-novae.fr/xperia_orange/scripts/android_ckeck_user.php");
        try{

            List<NameValuePair> nameValuePairs = new ArrayList<NameValuePair>(2);
            nameValuePairs.add(new BasicNameValuePair("id", "12345"));
            nameValuePairs.add(new BasicNameValuePair("stringdata", "AndDev is Cool!"));
            httppost.setEntity(new UrlEncodedFormEntity(nameValuePairs));   


        HttpResponse response = httpclient.execute(httppost);

        /*Checking response*/
        if(response!=null)
        {
            InputStream in = response.getEntity().getContent();
            System.out.println("Resultat de la server:"+in);
        }
        }
        catch(ClientProtocolException e)
        {

        }
    catch (IOException e) {
        // TODO Auto-generated catch block
    }

这是来自服务器的答案:

Resultat de la server:org.apache.http.conn.EofSensorInputStream@44e067e0

有谁知道我做错了什么?

【问题讨论】:

    标签: android http


    【解决方案1】:

    您不是在读取流,而是在查看底层InputStream 对象的String 表示。

    您会想阅读InputStream 的内容。查看this question 了解如何执行此操作的示例。

    【讨论】:

      猜你喜欢
      • 2020-06-12
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2020-01-01
      • 2017-06-25
      • 2015-11-14
      • 1970-01-01
      • 2017-06-24
      相关资源
      最近更新 更多