How do I send a file in Android from a mobile device to server using http?

后端 未结 5 1200
执笔经年
执笔经年 2020-11-22 12:04

In android, how do I send a file(data) from a mobile device to server using http.

5条回答
  •  庸人自扰
    2020-11-22 12:48

    This can be done with a HTTP Post request to the server:

    HttpClient http = AndroidHttpClient.newInstance("MyApp");
    HttpPost method = new HttpPost("http://url-to-server");
    
    method.setEntity(new FileEntity(new File("path-to-file"), "application/octet-stream"));
    
    HttpResponse response = http.execute(method);
    

提交回复
热议问题