Created
May 22, 2012 09:03
-
-
Save tong/2767731 to your computer and use it in GitHub Desktop.
PHP HTTP proxy for XMPP/BOSH connections using CORS
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
header("Access-Control-Allow-Origin: *"); | |
header("Access-Control-Allow-Credentials: true "); | |
header("Access-Control-Allow-Methods: OPTIONS, GET, POST"); | |
header("Access-Control-Allow-Headers: Content-Type, Depth, User-Agent, X-File-Size, X-Requested-With, If-Modified-Since, X-File-Name, Cache-Control"); | |
$url = "http://example.com/http-bind"; // URI of the HTTP/BOSH gate to the XMPP server | |
$postdata = file_get_contents('php://input'); | |
$opts = array('http' => | |
array( | |
'method' => 'POST', | |
'header' => 'Accept:text/xml', | |
'header' => 'Content-type:text/xml', | |
'header' => 'Content-Length: '.strlen( $postdata ), | |
'content' => $postdata | |
) | |
); | |
$context = stream_context_create( $opts ); | |
$response = file_get_contents( $url, false, $context ); | |
echo $response; | |
?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Always make sure to put the CORS headers first, otherwise chrome is in trouble!