我正在尝试通过使用curl https://api.truevault.com/v1/vaults/00000000-0000-0000-0000-000000000000/blobs \ -X POST \ -u API_KEY | ACCESS_TOKEN:\ --form "file=@xray.pdf“\ -H "Content-Type:multipart/form-data”等效项创建blob来上载图像。“
如https://docs.truevault.com/BLOBs#create-a-blob上所述
HttpClient httpClient = new DefaultHttpClient();
Log.d(Kiwee.KIWEE_TAG,"Request is:"+request.getUrl());
//Request printed here is:
//https://api.truevault.com/v1/vaults/vault_id/blobs
HttpPost post = new HttpPost(request.getUrl());
String basicAuth = BASIC_AUTH+Base64.encodeToString(API_KEY.getBytes(),Base64.DEFAULT);
post.setHeader(AUTHORIZATION,basicAuth);
post.setHeader(CONTENT_TYPE,TYPE_MULTIPART_FORM_DATA);
file = new File(filePath);
//file path on android device of image taken
MultipartEntityBuilder entityBuilder = MultipartEntityBuilder.create().setMode(HttpMultipartMode.BROWSER_COMPATIBLE);
entityBuilder.addPart("file",new FileBody(file));
post.setEntity(entityBuilder.build());
HttpResponse response = httpClient.execute(post);它以一个错误的请求告终。以下是响应:
<html>
<head><title>400 Bad Request</title></head>
<body bgcolor="white">
<center><h1>400 Bad Request</h1></center>
<hr><center>nginx/1.6.2</center>
</body>
</html>使用curl equivalent时,请求成功。有什么建议我应该在java代码中进行修改吗?
发布于 2015-02-17 13:45:00
已解决:
String basicAuth=BASIC_AUTH+Base64.encodeToString(API_KEY.getBytes(),Base64.DEFAULT);更改为
String basicAuth = BASIC_AUTH + Base64.encodeToString((API_KEY+":"+EMPTY_STRING).getBytes(), Base64.NO_WRAP);https://stackoverflow.com/questions/28425981
复制相似问题