1

I am using Httpful PHP library from http://phphttpclient.com/ , here is my sample code :

$uri = "https://ideabiz.lk/apicall/token?grant_type=password&username=user&password=pwd&scope=PRODUCTION";

    $response= \Httpful\Request::post($uri)
                ->sendsJson()  
                ->addHeaders(array(
                                'Accept' => 'application/x-www-form-urlencoded',              
                                'Authorization' => 'Basic b28yWTJqNjJoSDN4dHdHNXVkZHhhd2RjWEhrYTp0Zlp5UU1NVEJTcGZiSGFDWFJmQTFvWTJCb2dh',              
                            ))                    
                ->send();  

    echo $response;

But it doesn't return anything. (Body should be empty here.) I have tried even like this

$url = "https://ideabiz.lk/apicall/token";

    $response = \Httpful\Request::post($url)
                ->sendsJson()
                ->authenticateWith('user', 'pwd')
                ->body('{
                             "grant_type":"password",
                             "scope":"PRODUCTION"
                         }')  
                ->addHeaders(array(
                                'Accept' => 'application/x-www-form-urlencoded',              
                                'Authorization' => 'Basic b28yWTJqNjJoSDN4dHdHNXVkZHhhd2RjWEhrYTp0Zlp5UU1NVEJTcGZiSGFDWFJmQTFvWTJCb2dh',              
                            ))                    
                ->send();  

    echo $response;

But, it returns nothing. What should I do ..?

Thisaru
  • 171
  • 1
  • 10

1 Answers1

0

Finally did like this

$url = "https://ideabiz.lk/apicall/token?grant_type=password&username=tcmolserviceapp&password=Srilanka201804&scope=PRODUCTION";
    $response = \Httpful\Request::post($url)
        ->expectsJSON()
        ->body('')
        ->addHeaders(array(
           'Content-Type' => 'application/x-www-form-urlencoded',
           'Authorization' => 'Basic b28yWTJqNjJoSDN4dHdHNXVkZHhhd2RjWEhrYTp0Zlp5UU1NVEJTcGZiSGFDWFJmQTFvWTJCb2dh'
        ))
        ->send();

   $access_token = $response->body->access_token;

Used ->expectsJSON() instead of ->sendsJson()

Thisaru
  • 171
  • 1
  • 10