Ben Alman has a simple proxy script that I used as a temporary workaround for this kind of situation.
Basically, it forwards GET and POST requests using curl.
http://benalman.com/projects/php-simple-proxy/
$url = $_GET['url']; $ch = curl_init( $url ); curl_setopt($ch, CURLOPT_VERBOSE, true); if ( strtolower($_SERVER['REQUEST_METHOD']) == 'post' ) { curl_setopt( $ch, CURLOPT_POST, true ); //curl_setopt( $ch, CURLOPT_POSTFIELDS, $_POST ); $vin = $_POST["vin"]; $subscriberProgramXML = $_POST["subscriberProgramXML"]; $data = array("vin" => $vin, "subscriberProgramXML" => $subscriberProgramXML); $data_string = json_encode($data); $httpHeader = array('Content-Type: application/json', 'Content-Length: ' .strlen($data_string)); curl_setopt( $ch, CURLOPT_POSTFIELDS, $data_string); curl_setopt($ch, CURLOPT_HTTPHEADER, $httpHeader); } curl_setopt( $ch, CURLOPT_FOLLOWLOCATION, true ); curl_setopt( $ch, CURLOPT_HEADER, true ); curl_setopt( $ch, CURLOPT_RETURNTRANSFER, true ); curl_setopt( $ch, CURLOPT_USERAGENT, $_GET['user_agent'] ? $_GET['user_agent'] : $_SERVER['HTTP_USER_AGENT'] ); list( $header, $contents ) = preg_split( '/([\r\n][\r\n])\\1/', curl_exec( $ch ), 2 ); $status = curl_getinfo( $ch ); curl_close( $ch ); // Set the JSON data object contents, decoding it from JSON if possible. $decoded_json = json_decode( $contents ); $data['contents'] = $decoded_json ? $decoded_json : $contents; // Generate appropriate content-type header. $is_xhr = strtolower($_SERVER['HTTP_X_REQUESTED_WITH']) == 'xmlhttprequest'; header( 'Content-type: application/' . ( $is_xhr ? 'json' : 'x-javascript' ) ); // Get JSONP callback. $jsonp_callback = $enable_jsonp && isset($_GET['callback']) ? $_GET['callback'] : null; // Generate JSON/JSONP string $json = json_encode( $data ); print $jsonp_callback ? "$jsonp_callback($json)" : $json;
this code is copied from the source php, but this is only part of the code. This illustrates the solution.
Richard Kenny
source share