PHP CURL不工作,但在复制粘贴时工作
我正在用HTTP API向其中一个sms网关提供商发送请求 但是我得到了403个禁止的错误。PHP CURL不工作,但在复制粘贴时工作,php,codeigniter,curl,Php,Codeigniter,Curl,我正在用HTTP API向其中一个sms网关提供商发送请求 但是我得到了403个禁止的错误。 禁止您没有访问此服务器上的API/WebMS/Http/v1.0a/index.php的权限。 我的代码:- $url="http://www.somesite.in/API/WebSMS/Http/v1.0a/index.php?username=".$GLOBALS['smsGatewayUsername']."&password=".$GLOBALS['smsGatewayPassword
禁止您没有访问此服务器上的API/WebMS/Http/v1.0a/index.php的权限。
我的代码:-
$url="http://www.somesite.in/API/WebSMS/Http/v1.0a/index.php?username=".$GLOBALS['smsGatewayUsername']."&password=".$GLOBALS['smsGatewayPassword']."&sender=".$GLOBALS['smsGatewaySenderId']."&to=".$mobileNumber."&message=".$message."&reqid=1&format=text&route_id=".$GLOBALS['smsGatewayRouteId']."&sendondate=".$GLOBALS['dateCustom']."&msgtype=unicode";
$curl = curl_init();
curl_setopt ($curl, CURLOPT_URL, $url);
curl_setopt($curl, CURLOPT_USERAGENT, "Mozilla/5.0 (Windows NT 6.1; rv:19.0) Gecko/20100101 Firefox/19.0");
curl_exec ($curl);
curl_close ($curl);
但是当cop粘贴到浏览器中时,$url
可以工作
我已经在xampp php.ini中启用了
extension=php_curl.dll
,我这样做了,并让代码正常工作。不是将参数作为URL传递,而是将其作为CURL中的postfield选项传递
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, "http://www.somesite.in/API/index.php");
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, "username=".$GLOBALS['smsGatewayUsername']."&password=".$GLOBALS['smsGatewayPassword']."&sender=".$GLOBALS['smsGatewaySenderId']."&to=".$mobileNumber."&message=".$message."&reqid=1&format=text&route_id=".$GLOBALS['smsGatewayRouteId']."&sendondate=".$GLOBALS['dateCustom']."&msgtype=unicode");
curl_exec($ch);
curl_close($ch);
我这样做了,让代码正常工作。不是将参数作为URL传递,而是将其作为CURL中的postfield选项传递
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, "http://www.somesite.in/API/index.php");
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, "username=".$GLOBALS['smsGatewayUsername']."&password=".$GLOBALS['smsGatewayPassword']."&sender=".$GLOBALS['smsGatewaySenderId']."&to=".$mobileNumber."&message=".$message."&reqid=1&format=text&route_id=".$GLOBALS['smsGatewayRouteId']."&sendondate=".$GLOBALS['dateCustom']."&msgtype=unicode");
curl_exec($ch);
curl_close($ch);
可能是因为会话是用浏览器创建的,所以它可以正常工作。从浏览器中清除该站点的Cookie和会话,然后重试相同的url。他们一定实现了某种身份验证方法,您需要在curl中传递它。这不是php/curl错误。服务器只是说不允许您发送此请求。您已回显了
$url
并在浏览器中进行了检查?请尝试在使用curl发送$url
之前对其进行url编码。所有身份验证参数都在url中传递。当我在浏览器中回显并粘贴url时,效果很好。我已经清除了缓存cookies和会话。可能是因为该会话曾经使用浏览器创建过,所以它可以正常工作。从浏览器中清除该站点的Cookie和会话,然后重试相同的url。他们一定实现了某种身份验证方法,您需要在curl中传递它。这不是php/curl错误。服务器只是说不允许您发送此请求。您已回显了$url
并在浏览器中进行了检查?请尝试在使用curl发送$url
之前对其进行url编码。所有身份验证参数都在url中传递。当我在浏览器中回显并粘贴url时,效果很好。我已清除缓存cookie和会话。