Google Translator Toolkit API Error (“Multipart must have Atom and media part”)

≯℡__Kan透↙ 提交于 2019-12-23 17:53:25

问题


I try upload document (srt subtitles) to Google Translator Toolkit via API. But I get an error: "Multipart must have Atom and media part". What's wrong?

My request:

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--

Answer:

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:


The HTTP/1.1 specification states that there should be an empty line separating the headers and the body.

Request (section 5) and Response (section 6) messages use the generic message format of RFC 822 [9] for transferring entities (the payload of the message). Both types of message consist of a start-line, zero or more header fields (also known as "headers"), an empty line (i.e., a line with nothing preceding the CRLF) indicating the end of the header fields, and possibly a message-body.

Your request should look like this:

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--


来源:https://stackoverflow.com/questions/5069872/google-translator-toolkit-api-error-multipart-must-have-atom-and-media-part

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!