我想在 Web 服务器上发送图片文件,但在运行此代码时出现错误。
hc = new DefaultHttpClient();
URI u = null;
try {
u = new URI(params[0]);
HttpPost hp = new HttpPost();
hp.setURI(u);
System.out.println("start");
MultipartEntity mp=new MultipartEntity(HttpMultipartMode.BROWSER_COMPATIBLE);
System.out.println("mul");
FileBody fb=new FileBody(new File("akash/res/drawable-hdpi/hp.jpg"),"image/jpg");
fb.getMediaType();
mp.addPart("picture",fb);
System.out.println("add picture");
hp.setEntity(mp);
System.out.println("set entity");
HttpResponse hr = null;
hr = hc.execute(hp);
System.out.println(hr.getStatusLine().getStatusCode());