-2

I am getting response in Postman with same url and token. I am sure that there is issue in Passing token with Post Request.

Can anyone help me?

Pratik Sule
  • 163
  • 4
  • 18
  • You can specify more details here, like what have you tried, excerpt of the code, etc – fruqi Apr 18 '17 at 08:45
  • public static AsyncHttpClient client = new AsyncHttpClient(); – Pratik Sule Apr 18 '17 at 08:48
  • 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); } – Pratik Sule Apr 18 '17 at 08:49
  • I am getting response in get request with same structure, i think problem is in post request – Pratik Sule Apr 18 '17 at 08:51

1 Answers1

0

May this code help you to post a request with token as header.!

    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;


    }
gStephin
  • 332
  • 3
  • 20