簡體   English   中英

PHP - 填寫表格並將請求發送到另一個網站

[英]PHP - fill form and send request to another website

如果任何網站沒有 API,我可以向網站發送 post&get 請求並獲取數據嗎?

例子 :

http://site1.com/

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

當我填寫文本框並按 Enter 時,輸出會顯示正確的數據。 但是當我在地址欄中編寫 GET 方法並發送請求時,輸出顯示不正確的數據。

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

並將我重定向到:

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

誰能解釋我為什么? 以及如何使用php發送請求以獲取數據?

你可以試試這個,看看回復:

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

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM