0

I am getting the error bellow when making a request to an api:

HTTP/1.1 401 Unauthorized Server: nginx/1.9.3 Date: Fri, 10 Feb 2017 12:04:35 GMT Content-Length: 0 Connection: keep-alive WWW-Authenticate: BASIC realm="application" X-Powered-By: Undertow 1 Set-Cookie: rememberMe=deleteMe; Path=/ecocashGateway-preprod; Max-Age=0; Expires=Thu, 09-Feb-2017 12:04:35 GMT Set-Cookie: PAYMENTS_CLUSTER=PAY_02; path=/

Here is my php and curl request:

$url = 'https://payonline.econet.co.zw/ecocashGateway-preprod/payment/v1/transactions/amount'; 
//Initiate cURL. 
$ch = curl_init($url);
curl_setopt($ch, CURLOPT_USERPWD, "$username:$password");
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "POST");
//Attach our encoded JSON string to the POST fields.
curl_setopt($ch, CURLOPT_POSTFIELDS, $jsonDataEncoded);
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 0);
curl_setopt($ch, CURLOPT_USERPWD, "$username:$password");
//Set the content type to application/json
curl_setopt($ch, CURLOPT_HEADER, 1);
curl_setopt($ch, CURLOPT_HTTPHEADER, array(
    'Content-Type: application/json',
    'Content-length:'.strlen($jsonDataEncoded))
);
Machavity
  • 30,841
  • 27
  • 92
  • 100
tendaitakas
  • 328
  • 5
  • 18
  • What is the value of $url? This is likely your problem since you're getting a "401 Unauthorized Server" error. – Ben Shoval Feb 10 '17 at 12:55
  • $url = 'https://payonline.econet.co.zw/ecocashGateway-preprod/payment/v1/transactions/amount'; / /Initiate cURL. $ch = curl_init($url); – tendaitakas Feb 10 '17 at 13:05
  • I don't know that there's anything we can do for you as it is now. The 401 seems to indicate your login is wrong. Check the duplicate, as there's a wealth of information on how to do this – Machavity Feb 10 '17 at 13:21
  • can i have the link to the duplicate? – tendaitakas Feb 10 '17 at 13:52

0 Answers0