PHP Proxy that handles both GET and POST without use of cURL
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:
- Must be PHP
- Cannot use cUR开发者_运维百科L -- my server config doesn't support it. Presumably this leaves fopen() but I'm open to alternatives.
- Must support both GET and POST requests
- Support both responses for either XML and JSON
I'e searched high and low for a solution but always find solutions that use cURL or doesn't support POST.
I'm currently using this which doesn't work for 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);
}
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.
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
精彩评论