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

使用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.

图片转代码服务由CSDN问答提供 功能建议

我正在尝试使用cURL从外部网站检索信息,但网站返回一个空白页。

我仔细观察了Chrome的网络功能,我认为我发现了问题,但我不知道如何修复它。 如下图所示,服务器发布到特定URL,然后重定向到另一个显示最终结果的URL。

这是我现在的代码:

  $ 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); 
 
 ncurl_close($ ch); 
   
 
 <  p>该网站是荷兰语,但我要做的是检查某个电子邮件,电话号码或银行帐号,看看他们是否参与了任何sc  ams,所以我希望获得用户在网站上提交表单后获得的信息。 
 
 

表格在本网站上: https://www.politie.nl/aangifte-of-melding-doen/controleer-handelspartij.html < / a>

我希望有人可以帮助我并感谢你的时间。

  • 写回答
  • 关注问题
  • 收藏
  • 邀请回答

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);
    
    已采纳该答案
    打赏 评论

相关推荐 更多相似问题