我在向api发出请求时收到错误:
HTTP / 1.1 401未经授权的服务器:nginx / 1。9。3日期:2017年2月10日星期五12:04:35 GMT内容长度:0连接:keep-alive WWW-Authenticate:BASIC realm =" application& #34; X-Powered-By:Undertow 1 Set-Cookie:rememberMe = deleteMe;路径= / ecocashGateway-preprod;最大年龄= 0; Expires = Thu,09-Feb-2017 12:04:35 GMT Set-Cookie:PAYMENTS_CLUSTER = PAY_02;路径= /
这是我的php和curl请求:
$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))
);