我创建了一个应用程序,用户在其中从图库中选择图像并将该图像上传到服务器。我尝试使用 Httprequest 库执行此操作。但我无法上传它。
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;
另外,如果我可以使用任何其他好的库来完成这项工作,请让我知道。
尝试此代码并在该库中添加 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();
}
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)