is there any method that I can retrieve data (eg, username and password) from PHP to a Java servlet? Thanks
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);
POST和GET很大程度上不依赖于所使用的语言,因此,如果我正确理解了您的问题,则可以在该页面上的PHP中使用$ _POST ['var']或Java中的request.getParameter(“ var”)接收POST数据。
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.