本文整理汇总了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;
}