I am trying to post data from PHP to a ASP page. This is the PHP code:
$url = 'test.asp';
$data = array('q' => 'test');
$options = array(
'http' => array(
'header' => "Content-type: application/x-www-form-urlencoded\r\n",
'method' => 'POST',
'content' => http_build_query($data)
)
);
$context = stream_context_create($options);
$result = file_get_contents($url, false, $context);
if ($result === FALSE) {
//Handle error
}
var_dump($result);
And this is the ASP page:
<%Response.Write(request("q"))%>
When I call the PHP page it prints <%Response.Write(request("q"))%>
. I am testing this structure on IIS with both classic Asp and Php installed.
While test.asp
is, in some contexts, a relative URL, it isn't here.
file_get_contents
will only make an HTTP request if you pass it an absolute URL (e.g. one starting with http://www.example.com/
).
Passing it a file name will cause it to read from the local filesystem, which bypasses any HTTP server module that would execute the ASP code.