Advertisement
Guest User

MW-API + Httpful

a guest
Apr 12th, 2017
289
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 0.85 KB | None | 0 0
  1.     // Login request
  2.     $sRequestUrl = 'http://MYURL/w/api.php?action=query&meta=tokens&type=login&format=json';
  3.     $oResponse = Request::post($sRequestUrl)
  4.         ->addHeader('User-Agent', 'MYUSERAGENT')
  5.         ->expectsJson()
  6.         ->send();
  7.     $sLoginToken = $oResponse->body->query->tokens->logintoken;
  8.     $oHeader = current($oResponse->headers);
  9.     $sCookie = $oHeader['set-cookie'];
  10.  
  11.     // Login confirm
  12.     $sRequestUrl = 'http://MYURL/w/api.php?action=login&format=json';
  13.     $aBodyData = array(
  14.         'lgname' => 'MYUSER@MYBOT',
  15.         'lgpassword' => 'MYBOTPASSWORD',
  16.         'lgtoken' => $sLoginToken
  17.     );
  18.     $oResponse = Request::post($sRequestUrl)
  19.         ->addHeader('User-Agent', 'MYUSERAGENT')
  20.         ->addHeader('Cookie', $sCookie)
  21.         ->expectsJson()
  22.         ->body(http_build_query($aBodyData))
  23.         ->send();
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement