简体   繁体   中英

PHP - fill form and send request to another website

if any website doesn't have API, can i able to send post&get request to website and get data?

Example :

http://site1.com/

<form action="/index.php" method="post">
<input type="text" name="send" id="submit" placeholder="Enter name">
</form>

when i fill the textbox and hit enter , the output show me correct data. but when i write GET method in address bar and send request, the output show me incorrect data.

http://site1.com/index.php?send=INPUT&id=

and redirect me to :

http://site1.com/?send=INPUT&id=

can anyone explain me why? and how to send request with php to get data?

You could try this, and look at the response:

$url = 'http://site1.com/index.php';
$data = ["send" => "Test"];
$ch = curl_init($url);

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);
var_dump($response);

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.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM