Загрузка файла Box API 400 неверный запрос

У меня проблема с использованием API Box для загрузки файлов. Я использую Java с Apache HttpClient (4.4). Насколько я могу судить, я все устанавливаю правильно, но всегда получаю ответ 400 Bad request.

Я могу предоставить более подробную информацию, если это необходимо, но вот вывод отладки, который включает данные запроса и ответа, как их видит 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

Кто-нибудь может увидеть, в чем проблема? Спасибо за любую помощь, Мартин


person user304582    schedule 29.07.2015    source источник


Ответы (1)


Во втором фрагменте пантомимы вы сказали, что тип контента является двоичным, но ваши данные на самом деле являются текстом. Это может быть одной из проблем с запросом.

person user1886323    schedule 31.07.2015