I've looked everywhere but can't find what I need so hence why I'm posting this question.
我到处寻找但找不到我需要的东西,所以我为什么要张贴这个问题。
I'm looking for code for a PHP proxy to help me effectively do cross-domain jquery requests but have these requirements:
我正在寻找PHP代理的代码,以帮助我有效地执行跨域jquery请求,但有这些要求:
- Must be PHP
- 必须是PHP
- Cannot use cURL -- my server config doesn't support it. Presumably this leaves fopen() but I'm open to alternatives.
- 无法使用cURL - 我的服务器配置不支持它。据推测,这会留下fopen(),但我对其他选择持开放态度。
- Must support both GET and POST requests
- 必须支持GET和POST请求
- Support both responses for either XML and JSON
- 支持XML和JSON的响应
I'e searched high and low for a solution but always find solutions that use cURL or doesn't support POST.
我在搜索解决方案中搜索高低,但始终找到使用cURL或不支持POST的解决方案。
I'm currently using this which doesn't work for POST:
我目前正在使用这个不适用于POST:
header('Content-type: application/json');
$daurl = $_GET['url'];
$handle = fopen($daurl, "r");
if ($handle) {
while (!feof($handle)) {
$buffer = fgets($handle, 4096);
echo $buffer;
}
fclose($handle);
}
2 个解决方案
#1
1
file_get_contents()
. See Example #4 at the linked page (PHP online docs) on how to do 'custom' requests using streams for POST and arbitrary HTTP headers.
file_get_contents()函数。请参阅链接页面上的示例#4(PHP在线文档),了解如何使用POST和任意HTTP标头的流执行“自定义”请求。
#2
0
in other for you to get quick answer, you first need to do some work yourself, then when you get stuck, you can post it here. The question is too broad to be answered. you are requesting for a complete solution, you won't get it
在其他方面你得到快速回答,你首先需要自己做一些工作,然后当你遇到困难时,你可以在这里发布。这个问题太广泛了,无法回答。你要求一个完整的解决方案,你不会得到它
#1
1
file_get_contents()
. See Example #4 at the linked page (PHP online docs) on how to do 'custom' requests using streams for POST and arbitrary HTTP headers.
file_get_contents()函数。请参阅链接页面上的示例#4(PHP在线文档),了解如何使用POST和任意HTTP标头的流执行“自定义”请求。
#2
0
in other for you to get quick answer, you first need to do some work yourself, then when you get stuck, you can post it here. The question is too broad to be answered. you are requesting for a complete solution, you won't get it
在其他方面你得到快速回答,你首先需要自己做一些工作,然后当你遇到困难时,你可以在这里发布。这个问题太广泛了,无法回答。你要求一个完整的解决方案,你不会得到它