0

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?

William
  • 19
  • 4
  • Yes you can for instance use curl in php and send a POST request to that endpoint, which will give you the full response as a string. You can then extract data from it. – Flame Apr 01 '20 at 11:21
  • 1
    *"but when i write GET method"* - Well, the form is using POST. Have you tried using POST to replicate what the form is doing? It's not really clear to me what specifically you're trying to do or what the problem is. – David Apr 01 '20 at 11:22
  • @Flame i use bottom answer and it worked. now how can i get specific data? how to extract? – William Apr 01 '20 at 12:03
  • Well it depends on the format. Could be JSON, could be XML, could be a full HTML page. There are enough resources available to find your solution for these. – Flame Apr 01 '20 at 12:28
  • @Flame when i use the code, output is full website. can you send any resource? – William Apr 01 '20 at 12:31
  • You can try `symfony/dom-crawler` or use regexes to extract what you need. I cant provide a closing answer for this since it all depends on your data. – Flame Apr 01 '20 at 12:46

1 Answers1

1

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);
wschopohl
  • 1,567
  • 1
  • 11
  • 18
  • It worked. output show me full website. how can i get specific data? – William Apr 01 '20 at 11:58
  • web scraping is the keyword you have to search to find answers. For example: https://stackoverflow.com/questions/9813273/web-scraping-in-php – wschopohl Apr 02 '20 at 09:59