1

我的代码创建了基本的 curl 句柄curl_init,然后设置了一些选项。然后我用这个句柄登录某个网站。我工作正常。当我登录时,我想访问网站上的一些资源,这些资源仅供登录的 int 用户使用。但我想同时使用curl_multi.

因此,在登录后curl_copy_handle,我使用以前登录的句柄,为复制的句柄设置新的 URL,并将复制的句柄添加到 curl 多句柄。

然后我执行 curl 多句柄 - 它可以正常工作,但无法访问成员资源 - curl_copy_handle() 似乎没有复制 cookie?

如何复制所有 cookie(在登录期间设置)以及 curl_copy_handle?

我没有在这里粘贴代码,因为它可以正常工作 - 我只需要使用多个句柄共享 cookie 的方法。

4

2 回答 2

0

presuming that you have the correct cookie value, going from the documentation you can use curl_setopt with the CURLOPT_COOKIE value to set them for the request.

curl_setopt($curlhandle, CURLOPT_COOKIE, "Name=Value");

curl-setopt function

So just call that on your handle before performing curl_copy_handle. (there's also CURLOPT_COOKIEFILE to specify a physical cookie you saved.

I haven't ever used this myself though.

于 2012-05-27T09:21:39.957 回答
0

在 curl_copy_handle 中使用 CURLOPT_COOKIEJAR 和 CURLOPT_COOKIEFILE。

于 2012-06-01T09:11:33.373 回答