本文整理汇总了PHP中HttpRequest::addPutData方法的典型用法代码示例。如果您正苦于以下问题:PHP HttpRequest::addPutData方法的具体用法?PHP HttpRequest::addPutData怎么用?PHP HttpRequest::addPutData使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类HttpRequest
的用法示例。
在下文中一共展示了HttpRequest::addPutData方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: request
function request($url, $options = array())
{
$url = "http://" . $this->host . ":" . $this->port . $url;
$method = HTTP_METH_GET;
$headers = array("Host" => $this->host, "Referer" => "http://localhost/", "Content-Type" => "application/json");
$params = '';
foreach ($options as $name => $option) {
switch ($name) {
case "method":
$method = $option;
break;
case "headers":
$headers = array_merge($option, $headers);
break;
case "params":
$params = http_build_query($option);
break;
case "postdata":
$post_data = $option;
break;
default:
trigger_error("Unknown http option: {$name}", E_USER_WARNING);
}
}
if (!empty($params)) {
$url = $url . "?" . $params;
}
$request = new HttpRequest($url, $method);
$request->setHeaders($headers);
if (isset($post_data)) {
if ($method == HTTP_METH_PUT) {
$request->addPutData($post_data);
} else {
if ($method == HTTP_METH_POST) {
$request->setRawPostData($post_data);
}
}
}
$json = $request->send()->getBody();
$data = json_decode($json, true);
if (isset($data['rows'])) {
$data = new CouchResult($data);
}
return $data;
}
示例2: sendRequest
protected function sendRequest($uri, $method, $data = null)
{
try {
$request = new HttpRequest("https://{$this->domain}.chargify.com{$uri}");
$request->setHeaders(array('Content-Type' => 'application/json', 'Authorization' => 'Basic ' . base64_encode("{$this->apiKey}:x")));
$request->setOptions(array('httpauth' => "{$this->apiKey}:x", 'timeout' => 45, 'connecttimeout' => 45, 'ssl' => array('version' => 1)));
$request->setMethod(constant("HTTP_METH_{$method}"));
if ($method == 'POST' && $data) {
$request->setBody($data);
}
if ($method == 'PUT') {
$request->addPutData($data);
}
} catch (Exception $e) {
//TODO:
throw $e;
}
$request->send();
if ($request->getResponseCode() == 500) {
throw new Exception("Unable to proceed your request at the moment. Please try again later.");
}
if ($request->getResponseCode() == 404) {
throw new Exception("Unable to proceed your request. Please contact billing@scalr.net to get help.");
}
return $request;
}