简体   繁体   English

CURL错误401-PHP版本是否会导致此问题?

[英]CURL Error 401 - Does PHP version cause this problem?

I have the following code: 我有以下代码:

$body = "<SOAP-ENV:Envelope>".$data."</SOAP-ENV:Envelope>";
$ch = curl_init($FD_Add);
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_HTTPHEADER, array("Content-Type: text/xml"));
curl_setopt($ch, CURLOPT_HTTPAUTH, CURLAUTH_BASIC);
curl_setopt($ch, CURLOPT_USERPWD, "WS******._.1:********");
curl_setopt($ch, CURLOPT_POSTFIELDS, $data);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0);
curl_setopt($ch, CURLOPT_SSLCERT, DIR_ROOT."ABCDEFG/Certs/WS******._.1.pem");
curl_setopt($ch, CURLOPT_SSLKEY, DIR_ROOT."ABCDEFG/Certs/WS******._.1.key");
curl_setopt($ch, CURLOPT_SSLKEYPASSWD, "ckp_***********");
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
$result = curl_exec($ch);
if($test_env){echo 'The result of your request is:<RESULT>'.$result.'</RESULT>br/>' ;}
curl_close($ch);

The response is an error 401 HTTP requires authentication. 响应是错误401 HTTP需要身份验证。 I have verified the user ID and Password to be correct. 我已验证用户ID和密码正确无误。 What I am wondering first is if the version of PHP could cause this error if it does not support CULROPT_AUTH as I am running PHP~v. 我首先想知道的是,如果我在运行PHP〜v时不支持CULROPT_AUTH,PHP版本是否会导致此错误。 3.4 which from what I read does not support this option. 3.4我所阅读的内容不支持此选项。

Anybody know if this could be the trouble? 有人知道这可能会带来麻烦吗?

You could probably fake it by issuing the basic auth header yourself: 您可能会自己发出基本的auth标头来伪造它:

$auth_header = "Authorization: Basic " . base64_encode("$user:$pass");
curl_setopt($ch, CURLOPT_HTTP_HEADER, $auth_header);

but that's only available since Curl 7.10.3 and later. 但这仅适用于Curl 7.10.3及更高版本。 Your stone-age PHP is most likely using an equally stone-age CURL. 您的石头时代的PHP最有可能使用同样石头时代的CURL。

Really... PHP 3.4 is the equivalent of driving around in a car bought from the Flintstones. 真的... PHP 3.4相当于从Flintstones购买的汽车行驶。 You should upgrade to something more modern, like a Model-T... those horseless carriages are pretty impressive. 您应该升级到更现代的产品,例如Model-T。那些无马车的确令人印象深刻。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM