gpt4 book ai didi

php - cURL 返回 302,而浏览器返回 200

转载 作者:搜寻专家 更新时间:2023-10-31 21:08:00 25 4
gpt4 key购买 nike

我有一个脚本,它使用大量 cURL 来登录站点并提交一系列表单,但是由于 cURL 请求返​​回 302 并重定向到 block /端点页面,该脚本最近停止工作。如果我使用浏览器执行相同的操作,则不会出现重定向,只有 200 OK。

我的 cURL 正在使用登录过程返回的 cookie,所以我认为 session 没有被删除。

我最初认为 CSRF token (某种)丢失,给定重定向位置,并且过程中的后续表单(使用浏览器)包含隐藏的 CSRF token 字段,但 URL 不需要发布数据。

cURL 和响应如下:

curl_setopt($ch, CURLOPT_URL, 'https://*******.********.co.uk/Dispatcher?menuid=pos_home'); 
curl_setopt ($ch, CURLOPT_COOKIEJAR, 'cookie.txt');
curl_setopt($ch, CURLOPT_HEADER, 0);
$content = curl_exec ($ch);
echo "CURL INFO : <BR/><pre>" ;
print_r(curl_getinfo($ch));

返回:

Array
(
[url] => https://*******.********.co.uk/Dispatcher?menuid=pos_home
[content_type] => text/html
[http_code] => 302
[header_size] => 253
[request_size] => 332
[filetime] => -1
[ssl_verify_result] => 20
[redirect_count] => 0
[total_time] => 0.142718
[namelookup_time] => 2.4E-5
[connect_time] => 2.4E-5
[pretransfer_time] => 9.0E-5
[size_upload] => 43
[size_download] => 327
[speed_download] => 2291
[speed_upload] => 301
[download_content_length] => -1
[upload_content_length] => 43
[starttransfer_time] => 0.142659
[redirect_time] => 0
[certinfo] => Array
(
)

[primary_ip] => nnn.nnn.nnn.nn
[primary_port] => 443
[local_ip] => nnn.nnn.nnn.nn
[local_port] => 53154
[redirect_url] => https://*******.********.co.uk/Dispatcher?menuid=badorMissingCSRFT

)

如果有人知道服务器为何或如何对浏览器请求的 cURL 做出不同的响应,我将不胜感激 - thanks.of

最佳答案

您需要遵循重定向:

curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true);

不遵循重定向的其他原因:

4.14 Redirects work in browser but not with curl!

curl supports HTTP redirects fine (see item 3.8). Browsers generally support at least two other ways to perform redirects that curl does not:

Meta tags. You can write a HTML tag that will cause the browser to redirect to another given URL after a certain time.

Javascript. You can write a Javascript program embedded in a HTML page that redirects the browser to another given URL.

There is no way to make curl follow these redirects. You must either manually figure out what the page is set to do, or you write a script that parses the results and fetches the new URL.

来源:http://curl.haxx.se/docs/faq.html#Redirects_work_in_browser_but_no

关于php - cURL 返回 302,而浏览器返回 200,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29021638/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com