【问题标题】:Android HTTPRequest CycleAndroid HTTPRequest 周期
【发布时间】:2011-09-12 07:40:00
【问题描述】:

我正在尝试将 JSON 发送到我的服务器并作为结果检索 JSON。 比如发送用户名和密码,取回token等内容。

这就是我为发送的 HTTP 请求所做的。我现在如何检索同一请求中的内容?

        HttpClient client = new DefaultHttpClient();

        HttpPost request = new HttpPost("http://192.168.1.5/temp/test.php");

        List<NameValuePair> value = new ArrayList<NameValuePair>();

        value.add(new BasicNameValuePair("Name", jsonStr));

        UrlEncodedFormEntity entity = new UrlEncodedFormEntity(value);

        request.setEntity(entity);

        HttpResponse res = client.execute(request);

        String[] status_String=res.getStatusLine().toString().trim().split(" ");
        //String hd=res.getFirstHeader("result").toString();

        //System.out.println("Res=" + res);
        Log.e("tag", ""+res.toString());
        if(status_String[1].equals("200")){
            isDataSent=true;

【问题讨论】:

    标签: android json httpclient http-post


    【解决方案1】:

    让我在 vvieux 的回答中添加更多内容:

    res.getEntity().getContent() 
    

    将返回您的 InputStream。

    【讨论】:

      【解决方案2】:
      String returnData = EntityUtils.toString(res.getEntity());
      

      【讨论】:

        【解决方案3】:

        您可以使用HttpEntity

        res.getEntity().getContent() 
        

        【讨论】:

          猜你喜欢
          • 1970-01-01
          • 2021-09-14
          • 1970-01-01
          • 2013-04-06
          • 1970-01-01
          • 2011-12-22
          • 1970-01-01
          • 2014-07-28
          • 2012-07-22
          相关资源
          最近更新 更多