首先,我使用 codeigniter 并使用 PhilSurgeon codeigniter-curl:http ://philsturgeon.co.uk/code/codeigniter-curl
我正在尝试 curl 并从另一个域的响应标头中获取 Set-Cookies。代码如下
$url = 'http://ib.adnxs.com/ptv?id=1403122&size=1x1';
$this->curl->create($url);
$this->curl->http_header('User-Agent', 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_6_8');
$options = array(CURLOPT_HEADER => 1);
$this->curl->options($options);
$vast= $this->curl->execute();
echo "<pre>"; print_r($vast);
返回这个:
Set-Cookie: sess=1; path=/; expires=Fri, 24-May-2013 01:58:10 GMT; domain=.adnxs.com; HttpOnly
Set-Cookie: icu=ChIItcsCEAoYASABKAEwsu_1jAUQsu_1jAUYAA..; path=/; expires=Wed, 21-Aug-2013 01:58:10 GMT; domain=.adnxs.com; HttpOnly
Content-Type: text/xml
Set-Cookie: anj=Kfu=8fG1aPCxrx)0s]#%2LcYUiWd4r$[-T_g+2'ti*zYQaYhJGno9P8*w:M5Uy0Hg2:=*oU[fy9; path=/; expires=Wed, 21-Aug-2013 01:58:10 GMT; domain=.adnxs.com; HttpOnly
但是从这个使用 firebug 的url你会看到有 4 个 Set-Cookies 标头响应
Set-Cookie:icu=ChIItcsCEAoYBSAFKAUwhND1jAUQhND1jAUYBA..; path=/; expires=Wed, 21-Aug-2013 00:51:16 GMT; domain=.adnxs.com; HttpOnly
Set-Cookie:anj=Kfu=8fG1aPDYS3+0s]#%2LcYUiWd4r$[-T_g+2'thuA$jWEA)yIwtO#ou!><v1GC]*h)%B*hFeR*i`dzw@x-0CY_hN>8<=/=PpF>B2sEM:U9)Egw$gpK<rU3V2sTQBPSK2CBFmAZ4fxWRa/zdHI[^``z>tsw['ZH`CLcww-vV^ufhcR)XmgkjKre#dUU5QfVO.L4fG9GFBu=<jK(f6singv3mi%6gt$7LnUry9e#5x9U`r72%WaCxZpz7-]WIMUV)VDDCc<SUs06To>Gz$A>!A#UF?AH^u[Op<V1s>I#n[aDEPs:sNe8^J#UA<zF-Jik).@gDsrSxfhcQju>xP$yFLD=::tzzS/UTdX!C/=v7)6Fp'>c:%:rUn#/mTw`N#7U9(rwFXkmv^qM'0_QMX_jew(sDj(>a@s0XLV(Y%hCGZ`WDyVH>**Uy08b!:1hy:3!?k; path=/; expires=Wed, 21-Aug-2013 00:51:16 GMT; domain=.adnxs.com; HttpOnly
Set-Cookie:uuid2=3617392369395966810; path=/; expires=Wed, 21-Aug-2013 00:51:16 GMT; domain=.adnxs.com; HttpOnly
Set-Cookie:sess=1; path=/; expires=Fri, 24-May-2013 00:51:16 GMT; domain=.adnxs.com; HttpOnly
我错过了最重要的 cookie,即 Set-Cookie:uuid2。我的代码在我如何卷曲 url 上是否有问题,或者我可能缺少一些 curl 参数?