PHP发送自定义HTTP请求 [英] PHP Send Custom HTTP Request

查看:196
本文介绍了PHP发送自定义HTTP请求的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何向网址为http:// [IP]:[Port] /?

How can I send a custom HTTP Request to a server whose URL is "http://[IP]:[Port]/"?

的服务器发送自定义HTTP请求是,而不是第一行是一个正常的GET或POST像这样:

What I mean is that, instead of the first line being a normal GET or POST like so:

GET /index.html HTTP/1.1
Host: www.example.com

如何替换为类似的东西: / p>

How can this be replaced with something just like:

CUSTOM
Host: [IP]

我不介意必要时使用任何额外的库,如cURL。

I don't mind having to use any additional libraries if necessary such as cURL.

更新:

我尝试使用以下cURL代码:

I've tried using the following cURL code:

$ch = curl_init();

curl_setopt($ch, CURLOPT_URL, "http://[IP]:[Port]/");
curl_setopt($ch, CURLOPT_PORT, [Port]);

curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
//curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "CUSTOM");

$output = curl_exec($ch);
curl_close($ch);      

print($output);

但它只是继续加载2分钟,直到它说内部错误(无论是否使用CURLOPT_CUSTOMREQUEST )。但是,如果我使用标准网站(例如 http://google.com ),它会正常工作。

But it just keeps loading for 2 minutes until it said internal error (both with and without using the CURLOPT_CUSTOMREQUEST). However, if I use a standard website such as http://google.com it'll work fine.

此外,我忘记提及,我的服务器使用的端口是7899,这是确定吗?在我的网络浏览器打开它,但cURL似乎不能。

Also I forgot to mention, the port my server is using is 7899, is this ok? Open it in my web browser fine, but cURL doesn't seem to be able to.

推荐答案

看起来没有什么问题你的代码。如果您使用的是共享托管服务提供商,请要求他们打开出站TCP端口7899.

Looks like there's nothing wrong with your code. If you're using a shared hosting provider, ask them to open up outbound TCP port 7899.

这篇关于PHP发送自定义HTTP请求的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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