【问题标题】:Sms api working on local server but not working on hosted serverSms api 在本地服务器上工作,但在托管服务器上不工作
【发布时间】:2014-03-01 17:39:20
【问题描述】:

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

不可接受 在此服务器上找不到请求资源 /components/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
}
?>

【问题讨论】:

  • examplems.com 是您自己的服务器吗?还是您的短信提供商的?
  • 这是我的短信提供商,实际站点是 www.nigerianbulksms.com

标签: php html curl


【解决方案1】:

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

curl_setopt($ch, CURLOPT_POSTFIELDS, $data);

所以用这个来改变它:

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

【讨论】:

  • 这是错误:不可接受 在此服务器上找不到请求资源 /components/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.nigerianbulksms.com 端口 80
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2017-02-22
  • 1970-01-01
  • 2021-04-28
相关资源
最近更新 更多