Example #1
0
 function testJsonPost()
 {
     $http = new HttpClient('http://localhost/coredev_testserver/post_json.php');
     $http->setContentType('application/json');
     $http->setDebug(true);
     $res = $http->post(array('str' => 'abc 123'));
     $this->assertEquals($res, 'str=abc+123');
 }
 static function shorten($input_url)
 {
     $temp = TempStore::getInstance();
     $res = $temp->get('goo.gl/' . $input_url);
     if ($res) {
         return $res;
     }
     $api_key = '';
     $http = new HttpClient('https://www.googleapis.com/urlshortener/v1/url');
     $http->setContentType('application/json');
     $res = $http->post(Json::encode(array('longUrl' => $input_url, 'key' => $api_key)));
     $res = Json::decode($res);
     if (isset($res->error)) {
         d($res->error->errors);
         throw new \Exception('Error code ' . $res->error->code . ': ' . $res->error->message);
     }
     $temp->set('goo.gl/' . $input_url, $res->id);
     return $res->id;
 }
Example #3
0
 private static function send($url, $cookies, RequestSet $set, $cookieTable)
 {
     $bits = parse_url($url);
     $host = $bits['host'];
     $port = isset($bits['port']) ? $bits['port'] : 80;
     $path = isset($bits['path']) ? $bits['path'] : '/';
     $conn = new HttpClient($host, $port);
     $conn->setCookies($cookieTable);
     $conn->setContentType("text/xml;charset=UTF-8");
     // Output ...
     $xml = $set->toXMLString();
     if (!$conn->post($path, $xml)) {
         throw new Exception("PLLClient send exception");
     }
     // Input ...
     $in_string = $conn->getContent();
     $cookieTable = $conn->getCookies();
     $resset = ResponseSet::parseXML($in_string);
     return $resset->getResponses();
 }
Example #4
0
 function  updatesmstpl($smstpltag,$smstpl)
 {
     $timestamp=$this->getUnixTimeStamp();
     $digest=md5("$this->appid".md5($this->appkey)."$timestamp");
     $data=Array("smstpl"=>$smstpl,"appid"=>$this->appid,"digest"=>$digest,"timestamp"=>timestamp,"smstpltag"=>$smstpltag);
     $sendata=Array("ac"=>"updatesmstpl","data"=>$data);
     $sendata=json_encode($sendata);
     $http=new HttpClient();
     $http->setContentType("application/json");
     $ret=$http->post($this->apiurl,$senddata);
     if(!$ret)
     {
         $this->errormsg=$ret;
         return FALSE;
     }
     $retobj=json_decode($ret);
     $errorcode=$retobj->{'errorcode'};
     if($errorcode=="0")
     {
         return $retobj->{'smstpltag'};
     }
     else {
         $this->errormsg=$ret;
         return FALSE;
     }
 }