本文整理汇总了PHP中HttpResponse::setResponse方法的典型用法代码示例。如果您正苦于以下问题:PHP HttpResponse::setResponse方法的具体用法?PHP HttpResponse::setResponse怎么用?PHP HttpResponse::setResponse使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类HttpResponse
的用法示例。
在下文中一共展示了HttpResponse::setResponse方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: post
public static function post($url, $params, $auth)
{
try {
if (!function_exists("curl_init") && !function_exists("curl_setopt") && !function_exists("curl_exec") && !function_exists("curl_close")) {
throw new Exception('CURL is required.');
}
$data = array("data" => $params->getJSONEncode(), "version" => Config::version);
$httpResponse = new HttpResponse();
ob_start();
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, self::get_furl($url));
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, http_build_query($data, '', '&'));
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, '0');
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, '0');
curl_setopt($ch, CURLOPT_HTTPHEADER, $auth);
curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, Config::timeout);
curl_exec($ch);
$httpResponse->setResponse(urldecode(ob_get_contents()));
$httpResponse->setCode(curl_getinfo($ch, CURLINFO_HTTP_CODE));
ob_end_clean();
if (curl_errno($ch)) {
curl_close($ch);
throw new Exception(curl_error($ch));
}
curl_close($ch);
return $httpResponse;
} catch (Exception $e) {
curl_close($ch);
throw new HttpException($e->getMessage());
}
}