谷歌翻译工具包API错误(“多部分必须有Atom和媒体部分”)

时间:2011-02-21 18:41:48

标签: php api gdata-api

我尝试通过API将文档(srt字幕)上传到Google Translator Toolkit。 但我得到一个错误:“Multipart必须有Atom和媒体部分”。怎么了?

我的要求:

POST /toolkit/feeds/documents HTTP/1.1
Host: translate.google.com
GData-Version: 1.0
Authorization: GoogleLogin Auth=[myauth]
Content-Length: 404
Content-Type: multipart/related; boundary=SKYqYanmBJWCtDU
Slug: test.srt
--SKYqYanmBJWCtDU
Content-Type: application/atom+xml; charset=UTF-8 

<?xml version='1.0' encoding='UTF-8'?> 
<entry xmlns="http://www.w3.org/2005/Atom" xmlns:gtt="http://schemas.google.com/gtt/2009/11"> 
  <title>test</title> 
  <gtt:sourceLanguage>en</gtt:sourceLanguage> 
  <gtt:targetLanguage>ru</gtt:targetLanguage> 
</entry> 
--SKYqYanmBJWCtDU
Content-Type: application/x-subrip

data
--SKYqYanmBJWCtDU--

答案:

HTTP/1.1 400 Bad Request
Content-Type: text/html; charset=UTF-8
Date: Mon, 21 Feb 2011 18:20:24 GMT
Expires: Mon, 21 Feb 2011 18:20:24 GMT
Cache-Control: private, max-age=0
X-Content-Type-Options: nosniff
X-Frame-Options: SAMEORIGIN
X-XSS-Protection: 1; mode=block
Server: GSE
Connection: close
Transfer-Encoding: chunked

27
Multipart must have Atom and media part
0

Link to Google Translator Toolkit Data API Reference Guide v1.0

1 个答案:

答案 0 :(得分:2)

HTTP/1.1 specification表示应该有一个空行分隔标题和正文。

  

请求(第5节)和响应(第6节)消息使用RFC 822 [9]的通用消息格式来传输实体(消息的有效负载)。两种类型的消息都包括一个起始行,零个或多个标题字段(也称为“标题”),一个空行(即CRLF前面没有任何内容的行),表示标题字段的结尾,可能还有一个消息体。

您的请求应如下所示:

POST /toolkit/feeds/documents HTTP/1.1
Host: translate.google.com
GData-Version: 1.0
Authorization: GoogleLogin Auth=[myauth]
Content-Length: 404
Content-Type: multipart/related; boundary=SKYqYanmBJWCtDU
Slug: test.srt

--SKYqYanmBJWCtDU
Content-Type: application/atom+xml; charset=UTF-8 

<?xml version='1.0' encoding='UTF-8'?> 
<entry xmlns="http://www.w3.org/2005/Atom" xmlns:gtt="http://schemas.google.com/gtt/2009/11"> 
  <title>test</title> 
  <gtt:sourceLanguage>en</gtt:sourceLanguage> 
  <gtt:targetLanguage>ru</gtt:targetLanguage> 
</entry> 
--SKYqYanmBJWCtDU
Content-Type: application/x-subrip

data
--SKYqYanmBJWCtDU--