本文整理汇总了PHP中HttpClient::setContentType方法的典型用法代码示例。如果您正苦于以下问题:PHP HttpClient::setContentType方法的具体用法?PHP HttpClient::setContentType怎么用?PHP HttpClient::setContentType使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类HttpClient
的用法示例。
在下文中一共展示了HttpClient::setContentType方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: testJsonPost
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');
}
示例2: shorten
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;
}
示例3: send
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();
}
示例4: updatesmstpl
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;
}
}