2017-04-18 49 views
-2

我使用相同的url和令牌在郵遞員中獲得響應。我確信在發送請求傳遞令牌方面存在問題。在使用基於令牌的身份驗證時使用帶有loopj庫的AsyncHttpClient發佈請求

任何人都可以幫助我嗎?

+0

您可以在這裏指定更多的細節,比如你嘗試過什麼,代碼的摘錄,等 – fruqi

+0

公共靜態AsyncHttpClient客戶端=新AsyncHttpClient(); –

+0

public static void doMergeAccount(RequestParams params,AsyncHttpResponseHandler handler){client.setTimeout(60000); client.addHeader(「Authorization」,「token -NNXRQmsT8TDEWcouAB」); client.post(hashtagDemo_BASE_URL +「request-merge?」,params,handler); } –

回答

0

這段代碼可以幫助你發送一個令牌作爲頭部的請求。

public HttpResponse makeRequest(String uri, String json) { 
     try { 
      HttpClient httpclient = new DefaultHttpClient(); 


      HttpClientStack.HttpPatch httpPatch = new HttpClientStack.HttpPatch(uri); // create new httpGet object 
      httpPatch.setHeader("Authorization", getAccessToken()); 

      httpPatch.setEntity(new StringEntity(json)); 
      httpPatch.setHeader("Content-Type", "application/json; charset=utf-8"); 

      HttpResponse response = httpclient.execute(httpPatch); 
      HttpEntity entity = response.getEntity(); 
      resCoupon = EntityUtils.toString(entity); 
      Log.d("requestride", resCoupon); 

      return new DefaultHttpClient().execute(httpPatch); 
     } catch (UnsupportedEncodingException e) { 
      e.printStackTrace(); 
     } catch (ClientProtocolException e) { 
      e.printStackTrace(); 
     } catch (IOException e) { 
      e.printStackTrace(); 
     } 

     return null; 


    } 
相關問題