
要在服务器上发送文本文件或图像文件,可以使用MultiPartEntity。
DefaultHttpClient localDefaultHttpClient = new DefaultHttpClient(); FileBody localFileBody = new FileBody(new File(this.picturePath), "image/jpg"); HttpPost localHttpPost = new HttpPost("http://website.com/path/...."); MultipartEntity localMultipartEntity = new MultipartEntity(HttpMultipartMode.BROWSER_COMPATIBLE); try { Log.d("picturepath", this.picturePath); localMultipartEntity.addPart("Email", new StringBody("emailid@gmail.com")); localMultipartEntity.addPart("password", new StringBody("password")); localMultipartEntity.addPart("phone", new StringBody("9875.......")); localMultipartEntity.addPart("profilepicture", localFileBody); localHttpPost.setEntity(localMultipartEntity); HttpResponse localHttpResponse = localDefaultHttpClient.execute(localHttpPost); System.out.println("responsepre" + localHttpResponse.getStatusLine().getStatusCode());}catch (Exception e) { Log.d("exception", e.toString()); }这是可行的,因为此代码是我的Running项目的一部分。
欢迎分享,转载请注明来源:内存溢出
微信扫一扫
支付宝扫一扫
评论列表(0条)