Ejemplo n.º 1
0
 public function testPostRequest()
 {
     $client = new Net_Http_Client();
     $client->post(self::HOST . '/basic/post', array("greeting" => "Hello", "from" => "Net_Http_Client"));
     $this->assertEquals(200, $client->getStatus());
     $this->assertContains("Hello back", $client->getBody());
 }
Ejemplo n.º 2
0
 /**
  * 搜索 
  * 
  * @param string $keyword, 关键字
  * @param int $type, 搜索类型: TYPE_SINGLE-单曲,TYPE_ALBUM-专辑, TYPE_ARTIST-艺人
  */
 public function search($keyword, $type = SELF::TYPE_SINGLE)
 {
     $url = $this->server . 'search/get/web?csrf_token=';
     $param['s'] = urlencode($keyword);
     $param['type'] = $type;
     $param['offset'] = 0;
     $param['limit'] = 100;
     $http = new \Net_Http_Client();
     // Set referer header
     $http->setHeader('Referer', 'http://music.163.com/search/');
     $body = $http->post($url, $param)->getBody();
     $res = json_decode($body, true);
     if (!isset($res['code']) || $res['code'] != 200) {
         $msg = isset($res['message']) ? $res['message'] : 'Failed to connect the api server.';
         //throw new UnexpectedValueException($msg);
         $res['status'] = 0;
         $res['message'] = $msg;
     }
     return $res;
 }