is there any method that I can retrieve data (eg, username and password) from PHP to a Java servlet? Thanks
2 Answers
Create a POST request in PHP:
Use cURL:
$ch = curl_init('http://www.example.com:8080/my-servlet/');
$data = '...' # the data you want to send
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, $data);
curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
$response = curl_exec($ch);
curl_close($ch);
A better, more concise approach, using pecl_http:
$response = http_post_data('http://www.example.com:8080/my-servlet/', $data);
2 Comments
CheeHow
thanks for your response. meanwhile i also need to GET that data by using java servlet. do you have any idea how to do it?
Ynhockey
GET can be passed through URL, so just redirect to: example.com:8080/my-servlet/?var=value&var2=value2
POST and GET pretty much do not depend on the language being used, so if I understand your question correctly, you can use either $_POST['var'] in PHP or request.getParameter("var") in Java on the page that receives the POST data.
2 Comments
CheeHow
oh, really? but both are on different host...i thought i need some http connection to retrieve the POST data?
Ynhockey
There are two possible scenarios here: either the POST data is sent from a form directly to a PHP or Java page (then you can simple access it like I said), or the POST data is sent from a form to a PHP page, and from there you want to send it to a Java page--in that case you need to use CURL and someone else has already shown that :)