예제 #1
0
 public function testGetHeadersNon200()
 {
     $json = UrlUtils::getHeaders("http://speedtest.wdc01.softlayer.com/downloads/testbob.zip", 5);
     $this->assertTrue(is_array($json));
     $this->assertTrue(array_key_exists('success', $json));
     $this->assertFalse($json['success']);
     $this->assertTrue(array_key_exists('message', $json));
     $this->assertTrue(array_key_exists('info', $json));
     $this->assertEquals('404', $json['info']['http_code']);
 }
 private static function getMojangMD5($MCVersion)
 {
     $url = 'https://s3.amazonaws.com/Minecraft.Download/versions/' . $MCVersion . '/' . $MCVersion . '.jar';
     $response = UrlUtils::getHeaders($url, 15);
     if (!empty($response)) {
         $response = str_replace('"', '', $response);
         $data = explode("\n", $response, 11);
         $headers = array();
         array_shift($data);
         foreach ($data as $part) {
             if (strpos($part, ':') !== FALSE) {
                 $middle = explode(": ", $part, 2);
                 $headers[trim($middle[0])] = trim($middle[1]);
             }
         }
         return $headers['ETag'];
     }
     return '';
 }