0

下面的请求失败了,我不知道为什么,有什么见解吗?

var atom = ["<?xml version='1.0' encoding='UTF-8'?>",
            '<entry xmlns="http://www.w3.org/2005/Atom" xmlns:docs="http://schemas.google.com/docs/2007">',
            '<category scheme="http://schemas.google.com/g/2005#kind"',
            ' term="http://schemas.google.com/docs/2007#document"/>',
            '<title>', titleDoc, '</title>',
            '</entry>'].join('');


xhr.open('POST', URI , true);
xhr.setRequestHeader('Content-type', 'application/atom+xml');
//xhr.setRequestHeader('GData-Version', '3.0');                                                                                     
xhr.setRequestHeader('X-Upload-Content-Length', '0');
xhr.setRequestHeader('Authorization', 'OAuth ' + google.getAccessToken());
xhr.send(atom);

这是来自服务器的请求/响应数据包

Request URL:https://docs.google.com/feeds/upload/create-session/default/private/full
Request Method:POST
Status Code:400 Bad Request
Request Payload
<?xml version='1.0' encoding='UTF-8'?><entry xmlns="http://www.w3.org/2005/Atom" xmlns:docs="http://schemas.google.com/docs/2007"><category scheme="http://schemas.google.com/g/2005#kind" term="http://schemas.google.com/docs/2007#document"/><title>test</title></entry>
Response Headersview source
cache-control:no-cache, no-store, must-revalidate
content-length:19
content-type:text/html; charset=UTF-8
date:Sun, 01 Jul 2012 06:46:21 GMT
expires:Fri, 01 Jan 1990 00:00:00 GMT
pragma:no-cache
server:HTTP Upload Server Built on Jun 14 2012 02:12:09 (1339665129)
status:400 Bad Request
version:HTTP/1.1

未注释 gdata 版本的休息,但这仍然没有在谷歌文档中创建文档

HTTP/1.1 200 OK
status: 200 OK
version: HTTP/1.1
cache-control: no-cache, no-store, must-revalidate
content-length: 0
content-type: text/html; charset=UTF-8
date: Sun, 01 Jul 2012 21:02:16 GMT
expires: Fri, 01 Jan 1990 00:00:00 GMT
location: https://docs.google.com/feeds/upload/create-session/default/private/full?convert=false&upload_id=AEnB2UoaVeHUGhiIgKm9fL-WL_Fd1DdAAh7rdYDx6G6cseLwHgAMBfkdt42kf9YiKFJ8q9tiZ8vLVUb3Sr-KVUZi01m3vY6ZUw
pragma: no-cache
server: HTTP Upload Server Built on Jun 14 2012 02:12:09 (1339665129)
4

1 回答 1

0

您可以使用简单上传来创建一个空文件,只需将您的 url 替换https://docs.google.com/feeds/default/private/full为 GData-Version 标头并取消注释即可。

另一种选择(推荐)是使用新的 Google Drive API 的files.insert方法。

于 2012-07-10T17:42:14.167 回答