Android的使用发送照片HttpPost / HTTPGET [英] Android send photo using HttpPost/HttpGet
本文介绍了Android的使用发送照片HttpPost / HTTPGET的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我需要发送从存储在SD卡到外部阿比一个文件中的照片。为了做到这一点,我使用下面的code:
I need to send a photo from a file stored in the SDCARD to an external Api. In order to do this, i'm using the following code:
String responseStr = null;
this.setMethod(request);
this.setParameters(tags, parameters, optional);
String requested = mUri.build().toString();
HttpHost host = new HttpHost(API_REST_HOST, -1,
HttpHost.DEFAULT_SCHEME_NAME);
Log.d(TAG, requested);
try {
HttpPost post = new HttpPost(requested);
File file = new File(filepath);
FileEntity fileentity;
if (filepath.substring(filepath.length()-3, filepath.length
()).equalsIgnoreCase("jpg")) {
fileentity = new FileEntity(file,"image/jpeg;");
fileentity.setChunked(true);
post.setEntity(fileentity);
}
post.addHeader("Content-Type", "image/jpeg;");
HttpResponse response = mClient.execute(host,post);
使用setMethod和setParameters是为了建立URI对象自己的方法。外部API采用良好的参数而不是相片。该公司预计,照片中的HttpBody现场。
"setMethod" and "setParameters" are own methods in order to build the Uri object. The external api takes well the parameters but not the photo. It's expecting the photo in a HttpBody Field.
你知道吗?谢谢
感谢
推荐答案
该问题可能是在内容类型分号:
The problem may be the semicolon in the content type:
fileentity = new FileEntity(file,"image/jpeg;");
^
这篇关于Android的使用发送照片HttpPost / HTTPGET的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文