如何使用xamp从我的localhost从php脚本调用.aspx https?

时间:2016-01-21 10:56:09

标签: php asp.net curl sms-gateway

我正在尝试从安装了xamp的localhost发送短信。 请求的页面位于https和.aspx页面上。 我收到错误:" HTTP错误400.请求格式错误。"或仅在某些情况下的空白页面。 Detaisl如下:

$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的每个组合。

我需要在没有任何帖子数据的情况下调用此网址并查看其响应。 而是获得一个空白页。

请注意,当我在浏览器中执行包含所有详细信息的网址时,它可以正常工作。

在这方面,有人可以帮助我。

谢谢你, 乌斯曼

1 个答案:

答案 0 :(得分:1)

首先对您的数据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);