Box API文件上传400错误请求

时间:2015-07-29 18:36:57

标签: java api upload box

我在使用文件上传框API时遇到问题。我在Apache HttpClient(4.4)中使用Java。据我所知,我正在正确设置所有内容,但我总是得到400 Bad请求响应。

如果需要,我可以提供更多详细信息,但这里是调试输出,包括HttpClient看到的请求和响应数据:

http-outgoing-2 >> POST /api/2.0/files/content HTTP/1.1
http-outgoing-2 >> Authorization: Bearer taMJdbLcm1gJmTdnUUctqU53lpRXlVEi
http-outgoing-2 >> Content-Length: 506
http-outgoing-2 >> Content-Type: multipart/form-data; boundary=NMMQjAsnXwlKj02hT5qkfGNSn7hoOE1T1nGpaV52
http-outgoing-2 >> Host: upload.box.com
http-outgoing-2 >> Connection: Keep-Alive
http-outgoing-2 >> User-Agent: Apache-HttpClient/4.4 (Java 1.5 minimum; Java/1.7.0_79)
http-outgoing-2 >> Cookie: box_visitor_id=55b9188c8618a3.22188589
http-outgoing-2 >> Accept-Encoding: gzip,deflate
http-outgoing-2 >> "POST /api/2.0/files/content HTTP/1.1[\r][\n]"
http-outgoing-2 >> "Authorization: Bearer taMJdbLcm1gJmTdnUUctqU53lpRXlVEi[\r][\n]"
http-outgoing-2 >> "Content-Length: 506[\r][\n]"
http-outgoing-2 >> "Content-Type: multipart/form-data; boundary=NMMQjAsnXwlKj02hT5qkfGNSn7hoOE1T1nGpaV52[\r][\n]"
http-outgoing-2 >> "Host: upload.box.com[\r][\n]"
http-outgoing-2 >> "Connection: Keep-Alive[\r][\n]"
http-outgoing-2 >> "User-Agent: Apache-HttpClient/4.4 (Java 1.5 minimum; Java/1.7.0_79)[\r][\n]"
http-outgoing-2 >> "Cookie: box_visitor_id=55b9188c8618a3.22188589[\r][\n]"
http-outgoing-2 >> "Accept-Encoding: gzip,deflate[\r][\n]"
http-outgoing-2 >> "[\r][\n]"
http-outgoing-2 >> "--NMMQjAsnXwlKj02hT5qkfGNSn7hoOE1T1nGpaV52[\r][\n]"
http-outgoing-2 >> "Content-Disposition: form-data; name="attributes"[\r][\n]"
http-outgoing-2 >> "Content-Type: text/plain; charset=US-ASCII[\r][\n]"
http-outgoing-2 >> "Content-Transfer-Encoding: 8bit[\r][\n]"
http-outgoing-2 >> "[\r][\n]"
http-outgoing-2 >> "{"name":"This-is-a-Temp-File1438193805638", "parent":{"id":"4108964579"}}"
http-outgoing-2 >> "[\r][\n]"
http-outgoing-2 >> "--NMMQjAsnXwlKj02hT5qkfGNSn7hoOE1T1nGpaV52[\r][\n]"
http-outgoing-2 >> "Content-Disposition: form-data; name="file"[\r][\n]"
http-outgoing-2 >> "Content-Type: application/octet-stream[\r][\n]"
http-outgoing-2 >> "Content-Transfer-Encoding: binary[\r][\n]"
http-outgoing-2 >> "[\r][\n]"
http-outgoing-2 >> "this is a test file for upload1438193805640"
http-outgoing-2 >> "[\r][\n]"
http-outgoing-2 >> "--NMMQjAsnXwlKj02hT5qkfGNSn7hoOE1T1nGpaV52--[\r][\n]"
http-outgoing-2 << "HTTP/1.1 400 Bad Request[\r][\n]"
http-outgoing-2 << "Content-Type: text/html;charset=UTF-8[\r][\n]"
http-outgoing-2 << "Content-Length: 0[\r][\n]"
http-outgoing-2 << "Date: Wed, 29 Jul 2015 18:16:45 GMT[\r][\n]"
http-outgoing-2 << "Age: 0[\r][\n]"
http-outgoing-2 << "Connection: keep-alive[\r][\n]"
http-outgoing-2 << "Server: ATS[\r][\n]"
http-outgoing-2 << "[\r][\n]"
http-outgoing-2 << HTTP/1.1 400 Bad Request
http-outgoing-2 << Content-Type: text/html;charset=UTF-8
http-outgoing-2 << Content-Length: 0
http-outgoing-2 << Date: Wed, 29 Jul 2015 18:16:45 GMT
http-outgoing-2 << Age: 0
http-outgoing-2 << Connection: keep-alive
http-outgoing-2 << Server: ATS

谁能看到问题出在哪里?感谢任何帮助,马丁

1 个答案:

答案 0 :(得分:0)

In your second mime chunk you have said the content type is binary but your data is actually text. This could be one issue with the request.