3

我想在 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());
4

1 回答 1

0

您是否在清单中授予了互联网使用权限?

<uses-permission android:name="android.permission.INTERNET" />
于 2013-08-06T17:42:25.327 回答