I have do post some information in cross domain . And i am achieving this thing by below code
<?php
function do_post_request($sendingurl, $data, $optional_headers = null) {
$params = array(
'http' => array(
'method' => 'POST',
'url' => $data
)
);
if ($optional_headers !== null) {
$params['http']['header'] = $optional_headers;
}
$ctx = stream_context_create($params);
$fp = @fopen($sendingurl, 'rb', false, $ctx);
if (!$fp) {
throw new Exception("Problem with $sendingurl, $php_errormsg");
}
$response = @stream_get_contents($fp);
if ($response === false) {
throw new Exception("Problem reading data from $sendingurl, $php_errormsg");
}
return $response;
}
$response = do_post_request('http://mag16.playtrickz.com/testing.php','http%3A%2F%2Fwww.facebook.com');
echo $response;
But it is not working .
On successful POST Request : It will display its value
otherwise it will show : nodata found.
Why it is not working and how to make them work .
Here is how I would write your function:
This has been re-built so that the data to send to the server and the headers are passed in as associative arrays. So you would build an array that looks like you would want
$_POSTto look in the remote script, and pass that in. You can also pass an array of additional headers to send, but the function will automatically add aContent-Type,Content-LengthandConnectionheader.So your request would be called like this: