我正在尝试创建一个基于从supermariomakerbookmark.nintendo.net网站收集的信息的排队系统。首先,我在URL中发出GET请求,以查找字段中显示的CSRF- https://supermariomakerbookmark.nintendo.net/courses/7E00-0000-0220-574B:
<meta name="csrf-token" content="xxxxxx">之后,我需要向https://supermariomakerbookmark.nintendo.net/courses/7E00-0000-0220-574B/play_at_later发出POST请求,在报头中传递CSRF-Token和Cookie。cookie由用户提供,并从数据库中检索。
下面是我的代码:
$cookie = DB::table('CONFIG')->select('cookies')->first()->cookies;
// get csrf token
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, "https://supermariomakerbookmark.nintendo.net/courses/$id");
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 0);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0);
$html = curl_exec($ch);
$dom = new \DOMDocument();
libxml_use_internal_errors(true);
$dom->loadHTML($html);
$metas = $dom->getElementsByTagName('meta');
for ($i = 0; $i < $metas->length; $i++){
$meta = $metas->item($i);
if($meta->getAttribute('name') == 'csrf-token')
$csrfToken = $meta->getAttribute('content');
}
$headers = array();
$headers[] = "X-CSRF-Token: $csrfToken";
$headers[] = "Cookie: $cookie";
curl_setopt($ch, CURLOPT_URL, "https://supermariomakerbookmark.nintendo.net/courses/$id/play_at_later");
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 0);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
$ret = curl_exec($ch);但是它不起作用,curl POST请求返回一个自定义的500错误页面,而不是200OK。我在Laravel的一个控制器中执行这段代码。
如果我尝试使用Postman发出POST请求,它可以工作。Ant ideia关于如何使其工作的想法?
发布于 2016-08-24 02:30:28
我在另一个网络服务上也遇到了类似的问题。在我的例子中,问题出在头的名称上。
尝试更改此代码并对其进行测试:
$headers = array();
$headers[] = "Cookie: X-CSRF-Token=$csrfToken";
$headers[] = "Cookie: X-CSRF-Token=$cookie";https://stackoverflow.com/questions/39107375
复制相似问题