0

is there any method that I can retrieve data (eg, username and password) from PHP to a Java servlet? Thanks

1

2 Answers 2

1

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);
Sign up to request clarification or add additional context in comments.

2 Comments

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?
GET can be passed through URL, so just redirect to: example.com:8080/my-servlet/?var=value&var2=value2
0

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

oh, really? but both are on different host...i thought i need some http connection to retrieve the POST data?
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 :)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.