1

我的 PHP 脚本使用 http_post_fields() 向另一台服务器发出 post 请求。以下是代码示例:

$g = http_post_fields("http://mysite.com", $some_array);

尽管脚本偶尔会起作用,但我经常会收到此错误:

 http_post_fields() [function.http-post-fields]: couldn't resolve host name; name lookup timed out 

我现在在函数中尝试了各种http地址,都导致这个错误。有谁知道我的麻烦的根源是什么?

4

2 回答 2

1

如果您有 ssh 访问权限,请在 shell 上尝试此命令ping mysite.com,看看是否有任何响应

可以有防火墙/代理服务器配置来防止从服务器发送 POST 请求

试试这个并检查域解析为 IP。

<?php
$ip = gethostbyname('www.example.com');

echo $ip;
?>

带有 HTTPRequest 的示例,它将回显状态代码

<?php
$r = new HttpRequest('http://www.example.com/', HttpRequest::METH_POST);
$r->addPostFields(array('param1' => 'value'));

try {
   $http_req->send();
} catch (HttpException $ex) {

}

$response_code = $http_req->getResponseCode();
 echo $response_code;
?>
于 2012-12-13T16:50:36.053 回答
0

Thanks for all the input Kasun. In the end, I got tired of this PECL library (where http_post_fields is defined) and I used cURL instead. The goal I'm reaching for here, is to request a security ticket from 1 server to another. Of course, the whole module works smoothly, now that I'm using cURL. Thanks again.

于 2012-12-14T15:55:30.717 回答