不能使用的Htt prequest库图片上传到服务器 [英] Not able to upload image to server using Httprequest library

查看:157
本文介绍了不能使用的Htt prequest库图片上传到服务器的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经创建了一个应用程序在用户选择多媒体资料中的图像和图像上传到server.I使用的Htt prequest Library.But即时通讯不能够上传它试图这样做。

I have created an app in which user select an image from gallery and that image is uploaded to the server.I tried doing it using Httprequest Library.But i m not being able to upload it.

code

HttpRequest request = HttpRequest.post ("https://beta135.hamarisuraksha.com/Web/MobileApp/PostImsafePrflPic.aspx").send ("MODE=PP" + "&ID=" + "8" + "&ext=.jpg" + f);
            request.part ("mode", "MODE=PP");
            request.part ("id", "&ID=34588A34-E969-4723-84FE-E5409B66A5B7");
            request.part ("ext", "&ext=.jpg");
            request.part ("file", f);
            String response = request.body ();
            Log.e ("Image Upload", "" + response);


            return response; 

此外,如果有其他好的图书馆,我可以用它来完成这项工作,PLZ还是让我知道了。

Also if there is any other good library which i can use to do this work,plz lemme know.

推荐答案

试试这个code和这个库添加httpmime-4.1-beta1.jar:

Try This code and this library add httpmime-4.1-beta1.jar :

String url = "Your Url";


            HttpClient client = new DefaultHttpClient();
            client.getParams().setParameter(
                    CoreProtocolPNames.PROTOCOL_VERSION, HttpVersion.HTTP_1_1);
            HttpPost postMethod = new HttpPost(url);


            MultipartEntity entity = new MultipartEntity();

              entity.addPart("fname", new StringBody("xyz"));

            try {

                    File file1 = new File("Your image Path");
                    FileBody bin1 = new FileBody(file1, "images/jpeg");

                    entity.addPart("file", bin1);

                postMethod.setEntity(entity);
                HttpResponse response;
                response = client.execute(postMethod);

                String result = EntityUtils.toString(response.getEntity());

            }

            catch (Exception e) {
                // TODO Auto-generated catch block
                e.printStackTrace();
            }

这篇关于不能使用的Htt prequest库图片上传到服务器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆