0

I am trying to connect with the web service with PHP and in the web service log, I can see message: Credentials Basic xxxxxxxxxxxxxxxx: rejected.

However If I try to connect with same credentials, on same web service with Postman, it works, and result is returned. In the Postman, in the header I have:

Key: Authorization Value : Basic xxxxxxxxxxxxxxxx

Here is my PHP

    $verb = "GET"; 
    $ch = curl_init();
    curl_setopt($ch, CURLOPT_CUSTOMREQUEST, $verb);                
    curl_setopt($ch, CURLOPT_HTTPAUTH, CURLAUTH_BASIC);
    curl_setopt($ch, CURLOPT_USERPWD, "Basic xxxxxxxxxxxxxxxx");
    curl_setopt($ch, CURLOPT_URL, $webServiceUrl);
    //curl_setopt($ch, CURLOPT_POST, 1);// set post data to true
    curl_setopt($ch, CURLOPT_POSTFIELDS,urlencode($address));   // post data
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
    $json = curl_exec($ch);
    echo 'Curl error: ' . curl_error($ch) .'<hr>'; // This line prints Curl error:
    curl_close ($ch);
    $obj = json_decode($json);
    var_dump($obj); // This line prints NULL

Can anyone on base on this code points me what I am doing wrong?

user2417624
  • 653
  • 10
  • 32
  • Do these credentials work when you manually log in? Seems a bit weird to include the Basic phrase, but I am not familiar with the system you are trying to log into. – RST May 29 '20 at 10:39
  • Credentials work with I use postman. I can not log otherwise. Either with postman or PHP. I can get results with postman, but not with PHP. – user2417624 May 29 '20 at 10:41
  • take a look here https://stackoverflow.com/questions/12331224/how-to-include-authorization-header-in-curl-post-http-request-in-php – RST May 29 '20 at 10:52
  • Does this answer your question? [How do I make a request using HTTP basic authentication with PHP curl?](https://stackoverflow.com/questions/2140419/how-do-i-make-a-request-using-http-basic-authentication-with-php-curl) – JamesG May 29 '20 at 13:58

0 Answers0