Home  >  Article  >  Backend Development  >  curl模拟post数据有关问题

curl模拟post数据有关问题

WBOY
WBOYOriginal
2016-06-13 12:51:34817browse

curl模拟post数据问题
模拟登陆一个页面,用html写一个表单post过去能够登陆,但是用curl就登陆不了。这是什么情况


------解决方案--------------------
你的错误时只执行了一次 curl_exec($ch)
按现在登录页的设计,用户登录的流程是:
1、进入表单页 在这里sessionid已经传过来了,或与还有token
2、填写表单并提交
3、验证用户是否合法 验证通过后重新设置cookie

你只从第二步开始,那么 CURLOPT_COOKIEJAR 得到的只是第三步产生的cookie
由于缺少第一步的cookie,所以验证不会通过

所以你需要
1、进入表单页,通过 CURLOPT_COOKIEJAR 记录下 cookie
2、进入表单处理页,通过 CURLOPT_COOKIEFILE 传递第一步保存的 cookie
Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn