开发者

Android send photo using HttpPost/HttpGet

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

Any idea? Thanks

Thanks


The problem may be the semicolon in the content type:

fileentity = new FileEntity(file,"image/jpeg;");
                                            ^
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜