关于CURL请求

时间:2014-03-17 18:45:16

标签: android json curl

我必须使用CURL请求来解析使用android应用程序的API链接。在响应中我得到一个id和用户名作为输出。但是,我必须显示来自该API的令牌值。该令牌显示在Linux机器上在运行curl时我没有在windows机器上获取令牌值。我使用了这样的代码:

HttpClient httpclient = new DefaultHttpClient();
  HttpPost httppost = new HttpPost("http://moneyplayer.herokuapp.com/users.json");
  JSONObject json_one,json;

   json_one = new JSONObject();
   json =new JSONObject();                  

    json.put("password","userPwd");
    json.put("username","userEmail");
    json_one.put("user",json);
    Log.v("JSON Response is",""+json_one);
    StringEntity se = new StringEntity(json_one.toString());
    se.setContentType(new BasicHeader(HTTP.CONTENT_TYPE, "application/json"));
    httppost.setEntity(se);             
    httppost.setHeader("Content-type","application/json");
       // Execute HTTP Post Request
    HttpResponse response = httpclient.execute(httppost);       
    String responseStr = EntityUtils.toString(response.getEntity());
    Log.v("Response String Value is",""+responseStr);

在Linux机器中,输出显示如下:

{"id":37,"username":"testing123@1234.com"}
HTTP/1.1 200 O4 Cache-Control:max-age=0, private, must-revalidate 
Content-Type:application /json;
charset=utf-8 Date: Mon, 17 Mar 2014 15:33:51 GMT 
Etag:"a8979713bed4432cb624cb404df16a53"
Set-Cookie:
remember_token=BAhbCGkqSSIlMTZkYmE4ZDhhZTA2YzI2OWQwZjM2Y2ZjZjNmY2YyZGUGOgZFRjA%3D--d29db574adf7a4df8671eb75f43166101b81ef65; path=/; expires=Fri, 17-Mar-2034 15:33:51 GMT
Set-Cookie:
_live_local_web_session=BAh7B0kiCmZsYXNoBjoGRVRvOiVBY3Rpb25EaXNwYXRjaDo6Rmxhc2g6OkZsYXNoSGFzaAk6CkB1c2VkbzoIU2V0BjoKQGhhc2h7BjoOc3VjY2Vzc2VzVDoMQGNsb3NlZEY6DUBmbGFzaGVzewY7ClsGSSIiU3VjY2Vzc2Z1bGx5IGNyZWF0ZWQgcHJvZmlsZS4GOwBUOglAbm93bzokQWN0aW9uRGlzcGF0Y2g6OkZsYXNoOj

0 个答案:

没有答案