本文整理匯總了PHP中Parse\ParseClient::_getRequestHeaders方法的典型用法代碼示例。如果您正苦於以下問題:PHP ParseClient::_getRequestHeaders方法的具體用法?PHP ParseClient::_getRequestHeaders怎麽用?PHP ParseClient::_getRequestHeaders使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類Parse\ParseClient
的用法示例。
在下文中一共展示了ParseClient::_getRequestHeaders方法的1個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的PHP代碼示例。
示例1: upload
private function upload()
{
$fileParts = explode('.', $this->getName());
$extension = array_pop($fileParts);
$mimeType = $this->mimeType ?: $this->getMimeTypeForExtension($extension);
$headers = ParseClient::_getRequestHeaders(null, false);
$url = ParseClient::getAPIUrl() . 'files/' . $this->getName();
$rest = curl_init();
curl_setopt($rest, CURLOPT_URL, $url);
curl_setopt($rest, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($rest, CURLOPT_BINARYTRANSFER, 1);
$headers[] = 'Content-Type: ' . $mimeType;
curl_setopt($rest, CURLOPT_POST, 1);
curl_setopt($rest, CURLOPT_POSTFIELDS, $this->getData());
curl_setopt($rest, CURLOPT_HTTPHEADER, $headers);
$response = curl_exec($rest);
$contentType = curl_getinfo($rest, CURLINFO_CONTENT_TYPE);
if (curl_errno($rest)) {
throw new ParseException(curl_error($rest), curl_errno($rest));
}
curl_close($rest);
if (strpos($contentType, 'text/html') !== false) {
throw new ParseException('Bad Request', -1);
}
$decoded = json_decode($response, true);
if (isset($decoded['error'])) {
throw new ParseException($decoded['error'], isset($decoded['code']) ? $decoded['code'] : 0);
}
return $decoded;
}