命令行版本正常工作时,php curl被拒绝 [英] php curl gets refused while command line version is working

查看:236
本文介绍了命令行版本正常工作时,php curl被拒绝的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是来这里写书的新手,但是在过去几年里,我读了很多答案,所以首先:感谢您到目前为止给我的很多帮助!因此,这就是今天让我发疯的原因,无法在任何地方找到答案:

I'm new here to write, but read lots of answers in the past few years, so first of all: thanks for the lot of help you gave me so far! So, this is what makes me crazy today, and couldn't find the answer anywhere:

我有一个Web服务(一个Openfire插件)和一个基于LAMP的后台(在单独的盒子上),可以远程管理Openfire.将Openfire迁移到新的(第3个)框后,后台代码停止工作.这是一个代码段:

I have a web service (an Openfire plugin) and a LAMP-based backoffice (on a separate box), which manages the Openfire remotely. After migrating the Openfire to a new (3rd) box, the backoffice code stopped working. Here is a snippet:

<?php
    header("Content-Type: text/plain");

    $url = "http://gbbackup.dyndns.org:9090/plugins/goldsteinAdmin/goldsteinadmin"; echo $url."\n";

    $ch = curl_init($url); echo "handle: ".$ch."\n";
    curl_setopt($ch, CURLOPT_VERBOSE, true);
    curl_setopt($ch, CURLOPT_STDERR, fopen('php://stdout', 'w'));
    $result = curl_exec($ch); echo "Result: ".$result."\n";
    if ($result === false) echo 'cURL error '.curl_errno($ch).': '.curl_error($ch)."\n";
    print_r(curl_getinfo($ch));
    curl_close($ch);
?>

Curl的详细输出为:

Curl's verbose output is:

* About to connect() to gbbackup.dyndns.org port 9090 (#0)
*   Trying 81.183.210.206... * Connection refused
* couldn't connect to host
* Closing connection #0

现在奇怪的是,如果我通过命令行尝试,它会完美运行:

Now the strange thing is if I try via command line, it works perfectly:

user@login01:~/public_html/gb$ curl -v "http://gbbackup.dyndns.org:9090/plugins/goldsteinAdmin/goldsteinadmin"
* About to connect() to gbbackup.dyndns.org port 9090 (#0)
*   Trying 81.183.210.206... connected
* Connected to gbbackup.dyndns.org (81.183.210.206) port 9090 (#0)
> GET /plugins/goldsteinAdmin/goldsteinadmin HTTP/1.1
> User-Agent: curl/7.21.0 (x86_64-pc-linux-gnu) libcurl/7.21.0 OpenSSL/0.9.8o zlib/1.2.3.4 libidn/1.15 libssh2/1.2.6
> Host: gbbackup.dyndns.org:9090
> Accept: */*
>
< HTTP/1.1 200 OK
< Expires: Thu, 01 Jan 1970 00:00:00 GMT
< Set-Cookie: JSESSIONID=12e1urcewodgr;Path=/
< Content-Type: application/json;charset=ISO-8859-1
< Transfer-Encoding: chunked
<
{"type":"error","msg":"RequestNotAuthorised"}
* Connection #0 to host gbbackup.dyndns.org left intact
* Closing connection #0

PHP和命令行curl之间有什么区别?我已经删除了所有多余的功能,只是为了测试连接本身,但必须保留一些区别.

What could be the difference between the PHP and the command line curl? I have removed all the fancy extras just to test the connection itself, but some difference must be remained.

我做了更多测试,结果如下:

I made some more tests, here are the results:

  • PHP可以卷曲到其他网站(例如google.com):有效
  • 将链接插入到我自己的计算机上的Chrome中:有效
  • 通过php system()测试的命令行卷曲:不起作用
  • 我也想通过tcpdump进行区别,但是在另一个具有root特权的框上,PHP和命令行版本都可以使用

似乎这两个盒子彼此不喜欢:-)

It seems just these two boxes do not like eachother :-)

提前感谢您的帮助!

推荐答案

使用PHP,您必须单独提供端口(不在URL中提供),例如:

With PHP you must provide the port separately (not in the URL) like:

$url = "http://gbbackup.dyndns.org/plugins/goldsteinAdmin/goldsteinadmin";
...
curl_setopt($ch, CURLOPT_PORT, 9090);
...

这篇关于命令行版本正常工作时,php curl被拒绝的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆