简体   繁体   English

PHP Curl不起作用

[英]PHP Curl Not working

I am new here and not a pro in php but need a small help. 我是新来的,不是php专业人士,但需要一点帮助。 Actually I was given a code by my service prodvider to upload on my hosting. 实际上,服务提供商为我提供了一个代码,可以将其上传到托管服务器上。 But when i uploaded that code on my hosting account it didnt work well and after contact the support I was told to use php curl code in some part to make it run. 但是,当我在托管帐户上上传该代码后,它无法正常运行,在与支持人员联系后,我被告知要使用php curl代码以使其运行。 can anyone please help me with the issue. 谁能帮我解决这个问题。

Original Code: 原始代码:

<?php

$MobileNumber=substr($_REQUEST['VerifiedNumber'],-10);

$APIKey="<Your Dial2verify API Key Here>";
$SenderID="<6 ALPHABETIC CHARACTERS ONLY>";
$Message="<Your SMS Text Here>";

echo `curl -XPOST "http://host/SMS/SEND/$APIKey/$SenderID/$MobileNumber" -d "Msg=$Message"`;

?>

I don't know how to make the above code into curl code to make it work. 我不知道如何将上面的代码转换为curl代码以使其工作。

Thanks :) 谢谢 :)

By using `, you are using CURL via command line. 通过使用`,您将通过命令行使用CURL。

1st, check if the CURL extension for php is installed properly on you environment. 1,检查您的环境中是否正确安装了php的CURL扩展名。 Check if something about CURL is available when you print <?php phpinfo();?> 在打印<?php phpinfo();?>时检查有关CURL的信息是否可用

2nd, if CURL is installed, check on php.net/curl to know how to use CURL. 第二,如果已安装CURL,请检查php.net/curl以了解如何使用CURL。

Here a simple example to call your webservice : 这是一个简单的示例,用于调用您的Web服务:

<?php
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL,"http://www.host.com/SMS/SEND/$APIKey/$SenderID/$MobileNumber");
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS,"Msg=This+is+my+text+message");
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);

$reply = curl_exec ($ch);

curl_close ($ch);


echo $reply;
?>

The reason it did not work was that you where trying to call the command line version of cURL (and also doing the call wrong). 它不起作用的原因是您尝试在其中调用cURL的命令行版本(并且也进行了错误的调用)。

The best way is to use the php cURL module to make this call. 最好的方法是使用php cURL模块进行此调用。 Verify first that it is installed by creating an info.php file with the contents 通过创建包含内容的info.php文件,首先验证它是否已安装

<?php phpinfo();

If cURL is present on that page you are good to go. 如果该页面上有cURL,那您就可以了。

Obviously I have not had the ability to test this code but something like this should work 显然,我没有能力测试此代码,但类似的东西应该可以工作

$msisdn   = substr($_REQUEST['VerifiedNumber'],-10);
$apiKey   = "<Your Dial2verify API Key Here>";
$senderId = "<6 ALPHABETIC CHARACTERS ONLY>";
$message  = "<Your SMS Text Here>";

$url = "http://host/SMS/SEND/$apiKey/$senderId/$msisdn";

$ch = curl_init();

    curl_setopt($ch, CURLOPT_URL, $url);
    curl_setopt($ch, CURLOPT_POST, true);
    curl_setopt($ch, CURLOPT_POSTFIELDS, array('Msg' => $message));
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);

    $result = curl_exec($ch);

curl_close($ch);

echo 'Response from server:';
print_r($result);

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

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