使用 cURL 时没有 XML 响应

发布于 2024-08-15 18:12:30 字数 2666 浏览 5 评论 0原文

PHP cURL enblaed 服务器拒绝显示 xml 响应是否有原因?我一直在编写一个脚本来将号码发布到拨号服务。我觉得使用 cURL 是最好的选择。

在 3 台不同的服务器上,每台服务器都运行不同版本的 PHP,我能够毫无问题地获得响应。但在特定的服务器上,无论我尝试多少次,我都只会得到空白响应。

这是有问题的脚本:

<?php
if ($_POST['request_callback'])
{
$customer_name      = cleaninput($_REQUEST['customer_name'],"text");
$debtor_id          = cleaninput($_REQUEST['debtor_id'],"number");
$telephone_number   = cleaninput($_REQUEST['customer_number'],"number");

$xml_request = '<?xml version="1.0" encoding="utf-8"?>';
$xml_request .= '<CallRequest>';
$xml_request .= '<ProjectName>Noble Test</ProjectName>';
$xml_request .= '<ContactNumberToDial>'.$telephone_number.'</ContactNumberToDial>';
if (isset($_POST['callme_now'])) {
    $xml_request .= '<DateTimeToDial></DateTimeToDial>';
} else {
    $xml_request .= '<DateTimeToDial>' . date('Y-m-d ' . $_POST['hour_select'] . ':' . $_POST['minute_select'] . ':s') . '</DateTimeToDial>';
}
$xml_request .= '<ListSource>WebLead</ListSource>';
$xml_request .= '<AgentName></AgentName>';
$xml_request .= '<AddToList>False</AddToList>';
$xml_request .= '<SpecificAgent>False</SpecificAgent>';
$xml_request .= '<DBField>';
$xml_request .= '<FieldName>Name</FieldName>';
$xml_request .= '<FieldValue>NobleTesting</FieldValue>';
$xml_request .= '</DBField>';
$xml_request .= '</CallRequest>';

$loginUsername = "username";
$loginPassword = "password";
//$user_agent    = "Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.8.1.1) Gecko/20061204 Firefox/2.0.0.1";

// Send using CURL
$ch = curl_init();
curl_setopt( $ch, CURLOPT_URL, "http://194.217.1.2/ClickToCall/CallRequest.asmx/Call");          // URL to post
//curl_setopt( $ch, CURLOPT_USERAGENT, $user_agent);
curl_setopt( $ch, CURLOPT_USERPWD, "$loginUsername:$loginPassword"); //login
curl_setopt( $ch, CURLOPT_HTTPAUTH, CURLAUTH_ANY);
// curl_setopt( $ch, CURLOPT_HEADER, 1);  // make sure we get the header
curl_setopt( $ch, CURLOPT_RETURNTRANSFER, 1 ); // return into a variable
curl_setopt( $ch, CURLOPT_POST, 1);
curl_setopt( $ch, CURLOPT_SSL_VERIFYPEER, false );    # required for https urls
curl_setopt( $ch, CURLOPT_POSTFIELDS, 'xmlString=' . urlencode($xml_request));
curl_setopt( $ch, CURLOPT_HTTP_VERSION, CURL_HTTP_VERSION_1_1);
curl_setopt( $ch, CURLINFO_HEADER_OUT, 1);
curl_setopt ($ch, CURLOPT_FOLLOWLOCATION, 1);
$result = curl_exec( $ch ); // runs the post
curl_close($ch);

}
?>

除了不发回响应的特定服务器之外,它在其他任何地方都运行良好。我还使用 Firebug 检查请求和响应标头,结果两者都是空的。

有人可以帮忙吗?

谢谢

詹姆斯

Is there a reason why a PHP cURL enblaed server will refuse to display xml responses? I have been working on a script to post numbers to a dialling service. I felt using cURL would be the best thing to do.

On 3 different servers, each running different versions of PHP, I am able to get responses with no problems. But on the particular server, no matter how many times I try, I just get a blank response.

This the script in question:

<?php
if ($_POST['request_callback'])
{
$customer_name      = cleaninput($_REQUEST['customer_name'],"text");
$debtor_id          = cleaninput($_REQUEST['debtor_id'],"number");
$telephone_number   = cleaninput($_REQUEST['customer_number'],"number");

$xml_request = '<?xml version="1.0" encoding="utf-8"?>';
$xml_request .= '<CallRequest>';
$xml_request .= '<ProjectName>Noble Test</ProjectName>';
$xml_request .= '<ContactNumberToDial>'.$telephone_number.'</ContactNumberToDial>';
if (isset($_POST['callme_now'])) {
    $xml_request .= '<DateTimeToDial></DateTimeToDial>';
} else {
    $xml_request .= '<DateTimeToDial>' . date('Y-m-d ' . $_POST['hour_select'] . ':' . $_POST['minute_select'] . ':s') . '</DateTimeToDial>';
}
$xml_request .= '<ListSource>WebLead</ListSource>';
$xml_request .= '<AgentName></AgentName>';
$xml_request .= '<AddToList>False</AddToList>';
$xml_request .= '<SpecificAgent>False</SpecificAgent>';
$xml_request .= '<DBField>';
$xml_request .= '<FieldName>Name</FieldName>';
$xml_request .= '<FieldValue>NobleTesting</FieldValue>';
$xml_request .= '</DBField>';
$xml_request .= '</CallRequest>';

$loginUsername = "username";
$loginPassword = "password";
//$user_agent    = "Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.8.1.1) Gecko/20061204 Firefox/2.0.0.1";

// Send using CURL
$ch = curl_init();
curl_setopt( $ch, CURLOPT_URL, "http://194.217.1.2/ClickToCall/CallRequest.asmx/Call");          // URL to post
//curl_setopt( $ch, CURLOPT_USERAGENT, $user_agent);
curl_setopt( $ch, CURLOPT_USERPWD, "$loginUsername:$loginPassword"); //login
curl_setopt( $ch, CURLOPT_HTTPAUTH, CURLAUTH_ANY);
// curl_setopt( $ch, CURLOPT_HEADER, 1);  // make sure we get the header
curl_setopt( $ch, CURLOPT_RETURNTRANSFER, 1 ); // return into a variable
curl_setopt( $ch, CURLOPT_POST, 1);
curl_setopt( $ch, CURLOPT_SSL_VERIFYPEER, false );    # required for https urls
curl_setopt( $ch, CURLOPT_POSTFIELDS, 'xmlString=' . urlencode($xml_request));
curl_setopt( $ch, CURLOPT_HTTP_VERSION, CURL_HTTP_VERSION_1_1);
curl_setopt( $ch, CURLINFO_HEADER_OUT, 1);
curl_setopt ($ch, CURLOPT_FOLLOWLOCATION, 1);
$result = curl_exec( $ch ); // runs the post
curl_close($ch);

}
?>

This runs well everywhere else but this particular server where a response is not sent back. I have also used Firebug to check the request and response headers and both turned out to be empty.

Can anyone help out?

Thanks

James

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

叹倦 2024-08-22 18:12:30

无论如何,我已经找到了问题的解决方案。看来拨号服务器不接受以 HEAD 请求开始的传输。我最终不得不修改脚本的某些部分才能将 CURLOPT_CUSTOMREQUEST 与 GET 结合使用。

至少这一次,我收到了回应。这样就成功了。

Anyway I have discovered the solution to the problem. It seems the dialling server did not accept transfers that started with HEAD request. I ended up having to modify some portions of my script to make use of the CURLOPT_CUSTOMREQUEST with GET.

At least this time, I am receiving a response. So that has done the trick.

芸娘子的小脾气 2024-08-22 18:12:30

尝试此操作以确保第四个框实际上已正确设置以服务网页:

从命令行终端:

$ telnet 194.217.1.2 80  (press enter)

您应该得到如下响应:

尝试 192.168.245.84...
连接到 194.217.1.2。
转义字符是“^]”。

输入:

GET /ClickToCall/CallRequest.asmx/Call HTTP/1.1 (press enter)
Host: 194.217.1.2 (press enter twice)

您应该得到类似这样的响应,其中可能包含不同的 HTML 信息:

HTTP/1.1 200 OK
日期:2009 年 12 月 16 日星期三 15:40:13 GMT
服务器:Apache/1.3.31(Unix)PHP/4.3.8
X-Powered-By: PHP/4.3.8
传输编码:分块
内容类型:text/html

248

网络质量保证主页

这里有一些东西

Try this to ensure the 4th box is actually setup properly to serve web pages:

From a command line terminal :

$ telnet 194.217.1.2 80  (press enter)

You should get a response like :

Trying 192.168.245.84...
Connected to 194.217.1.2.
Escape character is '^]'.

Type this in:

GET /ClickToCall/CallRequest.asmx/Call HTTP/1.1 (press enter)
Host: 194.217.1.2 (press enter twice)

You should get a response sort of like this with different HTML info likely:

HTTP/1.1 200 OK
Date: Wed, 16 Dec 2009 15:40:13 GMT
Server: Apache/1.3.31 (Unix) PHP/4.3.8
X-Powered-By: PHP/4.3.8
Transfer-Encoding: chunked
Content-Type: text/html

248

Network Quality Assurance Homepage

Some stuff here

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文