Sms api在本地服务器上工作但不在托管服务器上工作

时间:2014-03-01 17:39:21

标签: php html curl

在我的开发环境中,我启用了CURL。当我通过wamp服务器部署应用程序时,一切正常,我可以在连接到互联网时发送短信。 现在,当我在我的帐户上托管它时,它无法发送短信,而是显示错误显示在下面

不可接受 在此服务器上找不到所请求资源/com_spc/smsapi.php的适当表示。 此外,尝试使用ErrorDocument处理请求时遇到404 Not Found错误。 Apache / 2.2.26(Unix)mod_ssl / 2.2.26 OpenSSL / 1.0.1e-fips DAV / 2 mod_bwlimited / 1.4服务器www.examplesms.com端口80

下面是工作代码。

<?php
if(isset($_POST['submit'])){
$data = array(
        'username' => $_POST['username'],
        'password' => $_POST['password'],
        'sender'  => $_POST['sender'],
'recipient'  => $_POST['recipient'],
        'message'  => $_POST['message']
);


    // Send the POST request with cURL
    $ch = curl_init('http://www.examplesms.com/components/com_spc/smsapi.php');
    curl_setopt($ch, CURLOPT_POST, true);

    curl_setopt($ch, CURLOPT_POSTFIELDS, $data);


 curl_setopt ($ch, CURLOPT_FOLLOWLOCATION, 1);
  curl_setopt($ch, CURLOPT_RETURNTRANSFER,1);
    $result = curl_exec($ch); //This is the result from Textlocal


if(curl_exec($ch) === false) {
echo '<font color=red size=4><b>Message sending failed' . '</b></font><br />';
} else {
echo '<font color=orange size=4><b>Message sent successfully' . '</b></font><br />';
echo 'Total number of bytes downloaded: ' . curl_getinfo($ch,CURLINFO_SIZE_DOWNLOAD) . '<br />';
echo 'Total size of all headers received: ' . curl_getinfo($ch,CURLINFO_HEADER_SIZE) . '<br />';
}

curl_close($ch);

//var_dump($result);

print($result);
} else {




?>


                <form method="post"  style="margin: 5px; padding: 5px;">
                        <table width="100%" border="0" cellspacing="5px" cellpadding="3px">

     <tr>

                                <td><input name="username" type="hidden" id="username" value="" size="50" style="width: 400px;" /></td>
                        </tr>
                        <tr>

                                <td><input name="password" type="hidden" id="password" value="" size="50" style="width: 400px;" /></td>
                        </tr>                   
<tr>

                                <td><input name="sender" type="hidden" id="sender" size="50" style="width: 400px;" value=""/></td>
                        </tr>      
<tr>
                                <td>Reciever</td>
                                <td>

<input name="recipient" type="text" id="recipient" size="50" style="width: 400px;" value=""/>


</td>
                        </tr>


                        <tr>
                                <td>Message</td>
                                <td><textarea name="message" rows="4" cols="90" id="message" style="width: 400px; height: 120px;"></textarea></td>
                        </tr>

                        <tr>
                                <td> 

                                <td><input type="submit" name="submit" id="add_subcat" value="Send Now!" class="btn btn-info btn-small"></input> <input type="reset" name="Submit2" value="Reset" /></td>
                        </tr>
                </table>
                </form>
<?php
}
?>

1 个答案:

答案 0 :(得分:0)

您将数据直接作为数组发布。这意味着它使用多部分表单发布。

curl_setopt($ch, CURLOPT_POSTFIELDS, $data);

所以用这个改变它:

curl_setopt($ch, CURLOPT_POSTFIELDS, http_build_query($data));