CheeHow
CheeHow

Reputation: 925

POST data from PHP and GET data in java servlet

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

Upvotes: 0

Views: 2346

Answers (2)

Burhan Khalid
Burhan Khalid

Reputation: 174708

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);

Upvotes: 1

Ynhockey
Ynhockey

Reputation: 3932

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.

Upvotes: 0

Related Questions