dongzhiyong8577 2019-04-14 08:42
浏览 109
已采纳

使用cURL在外部网站上提交表单无效

I am trying to retrieve information from an external website using cURL, but the website returns a blank page.

I took a close looker at the network functionality Chrome has and I think I found the problem, but I have no idea how to fix it. As seen in the image below, the server posts to a specific URL and then redirects to another one showing the final result.

https://i.imgur.com/973MO4N.png

This is the code I have right now:

$ch = curl_init();

curl_setopt($ch, CURLOPT_URL,"https://www.politie.nl/aangifte-of-melding-doen/controleer-handelspartij.html?_hn:type=action&_hn:ref=r199_r1_r1_r1");
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS,"url=&query=test");
curl_setopt($ch, CURLOPT_HTTPHEADER, array('Content-Type: application/x-www-form-urlencoded'));
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);

echo curl_exec ($ch);

curl_close ($ch);

The website is in Dutch, but what I am trying to do is check a certain email, phone number or bank account number to see if they have been involved in any scams, so I would like to have the information that a user gets after submitting the form on the website.

The form is on this website: https://www.politie.nl/aangifte-of-melding-doen/controleer-handelspartij.html

I hope someone can help me and thank you for your time.

  • 写回答

1条回答 默认 最新

  • doujia6503 2019-04-14 10:17
    关注

    As was pointed out in one of the comments to your question, a redirect occurs after the form is submitted. But not only that - information transfer between the form submit request and the request after redirect happens through a session, with session id stored in a cookie, so in order to get the results you have to enable cookies, too.

    // follow redirects
    curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true);
    
    // store and send cookies
    $tmpfname = dirname(__FILE__).'/cookie.txt';
    curl_setopt($ch, CURLOPT_COOKIEJAR, $tmpfname);
    curl_setopt($ch, CURLOPT_COOKIEFILE, $tmpfname);
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?