nategood / httpful

A Chainable, REST Friendly, PHP HTTP Client. A sane alternative to cURL.
MIT License
1.74k stars 298 forks source link

Oauth headers with post() #295

Open Budsy opened 2 years ago

Budsy commented 2 years ago

It seems that using addHeader on a post call is not working for me. Can anyone see why?

This fails to execute, (white screen, even when wrapped in try/catch block.):

`

$response = \Httpful\Request::post($url . '?' . $data . '&is_quicksend=true') ->addHeader('Authorization', 'Zoho-oauthtoken ' . $access_token)
->expectsJson()
->sendsJson()
->send(); `

But the following with addHeader stubbed out succeeds in running the post, but of course will not authenticate with Zoho Sign:

`

       $response = \Httpful\Request::post($url . '?' . $data . '&is_quicksend=true') 

     // ->addHeader('Authorization', 'Zoho-oauthtoken ' .  $access_token) 

      ->expectsJson()

      ->sendsJson()

      ->send();`

The response payload coming back from Zoho Sign API in the latter case is:

{"code":9031,"message":"Ticket invalid","status":"failure"}

The token and header formation are valid when sent through Curl on a command line, so it's not the token or the header formation.

chrisfield490 commented 2 years ago

Have you tried removing 'Zoho-oauthtoken' and just leaving the $access_token?

This is a java example, so it may be this.

Java

Using Apache HTTPClient.

DefaultHttpClient httpclient = new DefaultHttpClient();

String url = "http://localhost";

HttpPost httpPost = new HttpPost(url);

httpPost.addHeader("Authorization" , "");

HttpResponse response = httpclient.execute(httpPost);

I hope its of some help, although i have never tried the api with zoho.