Advertisement
Guest User

curl

a guest
Apr 28th, 2014
346
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 2.04 KB | None | 0 0
  1. <?php
  2.  
  3.   $content = "";
  4.   $rss_url= "https://portal.yzu.edu.tw/vc2/global_cos.aspx";
  5.   $ch = curl_init();
  6.   curl_setopt($ch, CURLOPT_URL,$rss_url);
  7.   curl_setopt ($ch, CURLOPT_HEADER, 0);
  8.     curl_setopt($ch , CURLOPT_REFERER , $rss_url );
  9.    curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true);
  10.   curl_setopt($ch, CURLOPT_COOKIEJAR, "cookie.txt");
  11.   curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
  12.   curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
  13.   curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, false);
  14.   $content = curl_exec($ch);
  15.   //var_dump($rss_content)
  16.   curl_close($ch);
  17.  
  18.   //
  19.  
  20.   preg_match_all('/__VIEWSTATE" value="(.*)"/' , $content , $res );
  21.   $VIEWSTATE = $res[1][0];
  22.   preg_match_all('/__EVENTVALIDATION" value="(.*)" /', $content , $res);
  23.   $EVENTVALIDATION = $res[1][0];
  24.  
  25.  
  26.  
  27.   $POST_data = array('__VIEWSTATE' => $VIEWSTATE,
  28.                     '__EVENTVALIDATION' => $EVENTVALIDATION,
  29.                     'DDL_YM' => '103,1  ',
  30.                     'DDL_Dept' => '301',
  31.                     'DDL_Degree' => '0',
  32.                     'Q' => 'RadioButton1',
  33.                     '__EVENTTARGET'=> '',
  34.                     '__EVENTARGUMENT'=> '',
  35.                     '__LASTFOCUS'=> '',
  36.                     'agree'=>'',
  37.                     'Button1'=>'確定'
  38.                 );
  39.  
  40.   $ch = curl_init();
  41.   curl_setopt($ch, CURLOPT_URL,$rss_url);
  42.   curl_setopt ($ch, CURLOPT_HEADER, 0);
  43.   curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
  44.   curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
  45.   curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, false);
  46.   curl_setopt($ch, CURLOPT_POST, true);
  47.   curl_setopt($ch, CURLOPT_REFERER , $rss_url );
  48.   curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true);
  49.   curl_setopt($ch, CURLOPT_COOKIEJAR, "cookie.txt");
  50.   curl_setopt($ch, CURLOPT_COOKIEFILE, "cookie.txt");
  51.   curl_setopt($ch, CURLOPT_POSTFIELDS, http_build_query($POST_data));
  52.   $content = curl_exec($ch);
  53.  
  54.   print_r($content);
  55.   echo "<pre>";
  56.   var_dump(http_build_query($POST_data));
  57.   var_dump(curl_getinfo($ch));
  58.   echo "</pre>";
  59.   curl_close($ch);
  60.  
  61.   ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement