/**
  * @expectedException Exception
  */
 public function testTimeoutFail()
 {
     Unirest\Request::timeout(1);
     Unirest\Request::get('http://mockbin.com/delay/1000');
     Unirest\Request::timeout(null);
     // Cleaning timeout for the other tests
 }
Example #2
0
    public function testTimeoutSuccess()
    {
        Unirest\Request::timeout(3);

        $response = Unirest\Request::get('http://httpbin.org/delay/1');
        $this->assertEquals(200, $response->code);

        Unirest\Request::timeout(null); // Cleaning timeout for the other tests
    }
 public function getItems($options)
 {
     $headers = array('Cookie' => $this->webCookies, 'Timeout' => Unirest\Request::timeout(5));
     $response = Unirest\Request::get('https://steamcommunity.com/trade/' . $options['tradeId'] . '/receipt/', $headers);
     if ($response->code != 200) {
         die('Error get items. Server response code: ' . $response->code);
     }
     $body = $response->body;
     preg_match('/(var oItem;[\\s\\S]*)<\\/script>/', $body, $matches);
     if (!$matches) {
         die('Error get items: no session');
     }
     $temp = str_replace(array("\r", "\n"), "", $matches[1]);
     $items = array();
     preg_match_all('/oItem = {(.*?)};/', $temp, $matches);
     foreach ($matches[0] as $key => $value) {
         $value = rtrim(str_replace('oItem = ', '', $value), ';');
         $items[] = json_decode($value, 1);
     }
     return $items;
 }