Reputation: 12935
PostMethod postMethod = new PostMethod("http://abc.com/a.php");
postMethod.setRequestEntity(new InputStreamRequestEntity(new ByteArrayInputStream(someString.getBytes())));
HttpClient httpClient = initMultithreadedHttpClient(ConnectionTimeout,
SocketTimeout, MaxRetry);
httpClient.executeMethod(postMethod);
This is how I am sending data from Java client to PHP server.
How do I read it in PHP?
I tried to capture the data like this:
<?php
$fp = fopen("/opt/lampp/htdocs/input.txt","w");
ob_start();
print_r($_REQUEST);
print_r($_SERVER);
print_r(http_get_request_body());
fprintf($fp,"%s",ob_get_contents());
ob_end_clean();
fclose($fp);
?>
But it didn't really print the request data.
Upvotes: 0
Views: 251
Reputation: 14153
Try this function instead of http_get_request_body
:
function get_post_body() {
$body = '';
$fh = @fopen('php://input', 'r');
if ($fh)
{
while (!feof($fh))
{
$s = fread($fh, 1024);
if (is_string($s))
{
$body .= $s;
}
}
fclose($fh);
}
return $body
}
Upvotes: 1
Reputation: 490647
You can read raw POST data in PHP with...
$post = file_get_contents('php://input');
I prefer this method over the $HTTP_RAW_POST_DATA
global.
Upvotes: 0