簡體   English   中英

網址僅在PHP中使用curl執行的get參數:獲取錯誤

[英]Url With only get parameters executing with curl in php:getting error

我正在發送短信,通過php curl發送api。

<?php
$number='XXXXXX';
$message="Hello world";
$url='http://XXx/api/sendmsg.php?user=XXXXX&pass=XXX&sender=SPOTMT&phone='.$number.'&text='.$message.'&priority=ndnd&stype=normal';
echo $url;
echo httpGet($url);
function httpGet($url)
{
    $ch = curl_init();  

    curl_setopt($ch,CURLOPT_URL,$url);
    curl_setopt($ch,CURLOPT_RETURNTRANSFER,true);
    curl_setopt($ch,CURLOPT_HEADER, false); 

    $output=curl_exec($ch);

    curl_close($ch);
    return $output;
}

我將從api服務中收到錯誤消息,但是,當我直接在瀏覽器中從此echo $url復制url時,它將正常工作。 但是當使用curl我會收到錯誤消息。

就這個

發件人ID不存在,未決或路由無效!

curl沒有奏效。

將用戶代理添加到您的curl請求中,因為后端可能會過濾具有默認curl用戶代理的請求。

curl_setopt($ch,CURLOPT_USERAGENT,'Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.8.1.13) Gecko/20080311 Firefox/2.0.0.13');

使用urlencode()對消息進行編碼,然后再將其提交給CURL

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM