2016-01-21 26 views
1

我正尝试从安装了xamp的本地主机发送短信。 请求的页面位于https和.aspx页面上。 我收到错误:“HTTP错误400.请求形成严重。”或仅在某些情况下为空白页面。 Detaisl如下:如何使用xamp从本地主机的php脚本调用.aspx https?

$url = 'https://www.ismartsms.net/iBulkSMS/HttpWS/SMSDynamicAPI.aspx'; 
$postArgs = 'UserId='.$username. 
    '&Password='.$password. 
    '&MobileNo='.$destination. 
    '&Message='.$text. 
    '&PushDateTime='.$PushDateTime. 
    '&Lang='.$Lang; 
function getSslPage($url) { 
    $ch = curl_init(); 
    curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE); 
    curl_setopt($ch, CURLOPT_HEADER, false); 
    curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true); 
    curl_setopt($ch, CURLOPT_URL, $url); 
    curl_setopt($ch, CURLOPT_REFERER, $url); 
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, TRUE); 
    $result = curl_exec($ch); 
    curl_close($ch); 
    return $result; 
} 
$response = getSslPage($all); 

echo "<pre>"; 
print_r($response); exit; 

我想互联网上找到每一个可能的解决方案/组合,但未能解决这个问题。 API开发人员没有用于php脚本的示例。 我试过httpful php库和file_get_contents函数,但得到空白页面。还尝试了每个与curl_setup的组合。

我需要调用这个URL没有任何后期数据,并看到它的响应。 取而代之的是一个空白页面。

请注意,当我在浏览器中执行具有所有细节的url时,它工作正常。

任何人都可以在这方面帮助我。

谢谢 乌斯曼

+0

$ all = $ url。“?”。$ postArgs; $ response = getSslPage($ all); –

回答

0

先做urlencode您的数据如下:

$postArgs = 'UserId='. urlencode($username. 
'&Password='.urlencode($password). 
'&MobileNo='.urlencode($destination). 
'&Message='.urlencode($text). 
'&PushDateTime='.urlencode($PushDateTime). 
'&Lang='.urlencode($Lang); 

两个可能的解决方案之后。一种是使用GET

curl_setopt($ch, CURLOPT_URL, $url . "?" . $postArgs); 

第二种选择是使用POST方法。

curl_setopt($ch, CURLOPT_URL, $url); 
curl_setopt($ch, CURLOPT_POST, true); 
curl_setopt($ch, CURLOPT_POSTFIELDS, $postArgs); 
+0

谢谢@Sabuj回复。我尝试了一些组合,它的工作。如果有人曾经使用过此API,请添加代码。 –

+0

'code' $ url ='https://www.ismartsms.net/iBulkSMS/HttpWS/SMSDynamicAPI.aspx'; $ data = http_build_query('UserId'=> $ username,'Password'=> $ password,'MobileNo'=> $ destination,'Message'=> $ text,'PushDateTime'=> $ PushDateTime,'Lang '=> $ Lang)); $ requestData = $ url。“?”。$ data;'code' –