PHP解决方案的JSON响应和参数

时间:2013-06-11 07:22:43

标签: php javascript json curl

我觉得我采取这一步的每一步都有5个墙出现了它的乐趣,但也令人沮丧。

所以我试图通过cURL登录网站,经过大量的讨论和使用firefox开发工具后,我看到我的浏览器在JSON中响应。老实说,我对JSON一无所知,但我觉得如果我通过这个,我就会明白。

所以问题是我如何使用cURL模拟这些JSON响应?我只是复制并粘贴它们在数组中的内容吗?我是否在每个http请求中包含此数组,或者我是否单独执行这些操作。

如果你们想看到它,这是JSON代码。

__jsonp1__([{"id":"1","channel":"/meta/handshake","successful":true,"version":"1.0","supportedConnectionTypes":["long-polling","cross-origin-long-polling","callback-polling","websocket","eventsource","in-process"],"clientId":"adag3o01k7uyb0ub4s2v1h4r7fs1m3zfvp0","advice":{"reconnect":"retry","interval":0,"timeout":600000}}]);

__jsonp2__([{"id":"3","clientId":"adag3o01k7uyb0ub4s2v1h4r7fs1m3zfvp0","channel":"/meta/connect","successful":true,"advice":{"reconnect":"retry","interval":0,"timeout":600000}},{"id":"2","clientId":"adag3o01k7uyb0ub4s2v1h4r7fs1m3zfvp0","channel":"/meta/subscribe","successful":true,"subscription":"/user/11585628"}]);

__jsonp3__([{"id":"4","clientId":"adag3o01k7uyb0ub4s2v1h4r7fs1m3zfvp0","channel":"/meta/connect","successful":true,"advice":{"reconnect":"retry","interval":0,"timeout":600000}},{"channel":"/user/11585628","data":{"type":"subscribe"},"clientId":"adag3o01k7uyb0ub4s2v1h4r7fs1m3zfvp0","id":"5","authenticated":true}]);

_jsonp4__([{"id":"1","channel":"/meta/handshake","successful":true,"version":"1.0","supportedConnectionTypes":["long-polling","cross-origin-long-polling","callback-polling","websocket","eventsource","in-process"],"clientId":"uiqqkp0vf66rl0mlc8281ufknaw1qkcriu1","advice":{"reconnect":"retry","interval":0,"timeout":600000}}]);

这是我的代码我正在尝试一些事情,这就是为什么它看起来有点奇怪

<?php


$ckfile ='   __utma=173730677.1410450142.1370766442.1370882903.1370893342.8; __utmz=173730677.1370893342.8.6.utmcsr=web.groupme.com|utmccn=(referral)|utmcmd=referral|utmcct=/groups; __utma=64278953.892306882..1370882931.1370893339.9; __utmz=64278953.1370882931.8.4.utmcsr=groupme.com|utmccn=(referral)|utmcmd=referral|utmcct=/signin; _g=%3D%3D--772097f0c6a077ac0f904c981ba5523ddffef3d5; __utmc=64278953; __utmc=173730677; __utmb=64278953.1.10.1370893339; __utmb=173730677.2.10.1370893342';

$postfields = '{"username":"@gmail.com","password":"somepass","app_id":"groupme.com","grant_type":"password"}';
$postfields2 ='{"group":{"name":"test","memberships":[]}}';
$custom = 'X-Access-Token: CEbhaIkkKTc9dtVMpxyc2IZOfnzEoh5w4UTzsVSb';

$ch2 = curl_init();
$ch3 = curl_init();

$ch = curl_init();





curl_setopt_array(
    $ch,
    array(
    CURLOPT_SSL_VERIFYPEER => false,
    CURLOPT_URL => 'https://web.groupme.com/#access_token=some token',
    CURLOPT_COOKIE=> $ckfile,
    CURLOPT_USERAGENT =>'Mozilla/5.0 (Windows NT 6.1; WOW64; rv:21.0) Gecko/20100101 Firefox/21.0',
    CURLOPT_REFERER => 'https://groupme.com/signin',
    CURLOPT_RETURNTRANSFER => true, 
    //CURLOPT_FOLLOWLOCATION => true,
    CURLOPT_HTTPHEADER => array('Host: web.groupme.com','Accept: text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8','Accept-Language: en-US,en;q=0.5','Accept-Encoding: gzip, deflate')
    )
);


curl_setopt_array(
    $ch2,
    array(
    CURLOPT_SSL_VERIFYPEER => false,
    CURLOPT_URL => 'https://web.groupme.com/#access_token=some token',
    CURLOPT_COOKIE=> $ckfile,
    CURLOPT_USERAGENT =>'Mozilla/5.0 (Windows NT 6.1; WOW64; rv:21.0) Gecko/20100101 Firefox/21.0',
    CURLOPT_REFERER => 'https://groupme.com/signin',
    CURLOPT_RETURNTRANSFER => true, 
    //CURLOPT_FOLLOWLOCATION => true,
    CURLOPT_HTTPHEADER => array('Host: web.groupme.com','Accept: text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8','Accept-Language: en-US,en;q=0.5','Accept-Encoding: gzip, deflate','Content-Type=text/html;charset=utf-8','Server=thin 1.3.1 codename Triple Espresso','Strict-Transport-Security=max-age=31536000','X-Frame-Options=sameorigin','x-xss-protection=1; mode=block','Content-Length=24275')
    )
);



$response = curl_exec($ch2);
//curl_close($ch);  



echo '<pre>';
print_r($response);
echo '</pre>'
?>

0 个答案:

没有答案