任何人都知道如何使用curl将文件发布到google文档。 我写这段代码:
$header[] = "Authorization: GoogleLogin auth=seсretkey";
$header[] = "Content-Type: application/pdf";
$header[] = "Slug: testdoc";
$header[] = "Content-Length: ".$_FILES['file']['size']."";
$url = "http://docs.google.com/feeds/documents/private/full";
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, TRUE);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE);
curl_setopt($ch, CURLOPT_POST, TRUE);
curl_setopt($ch, CURLOPT_POSTFIELDS, file_get_contents($_FILES['file']['tmp_name']));
curl_setopt($ch, CURLOPT_HTTPHEADER, $header);
$response = curl_exec($ch);
$info = curl_getinfo($ch);
curl_close($ch);
只有当我使用普通/文本内容类型和文本文件时,它才能正常工作,但如果我在二进制模式下上传文件,则会收到417个http错误代码,例如pdf文档。
我正在尝试更改此行
curl_setopt($ch, CURLOPT_POSTFIELDS, file_get_contents($_FILES['file']['tmp_name']));
到此
curl_setopt($ch, CURLOPT_POSTFIELDS, array("file"=>"@".$_FILES['file']['tmp_name']));
但是我又得到了417个响应错误代码。只有普通/文本回复是201。
的Google文档上传标题示例POST /feeds/documents/private/full HTTP/1.1
Host: docs.google.com
Authorization: <your authorization header here>
Content-Length: 81047
Content-Type: application/vnd.ms-excel
Slug: Example Spreadsheet
... spreadsheet contents here ...
答案 0 :(得分:0)
结帐this article。它提供了关于如何使用CURL的精彩文章,包括如何发布变量。我不确定如何使用谷歌文档,但只要你按照他们的指示,这应该可以帮助你找出你的post var问题。