Android 使用httpClient POST 模拟发送 multipart表单内容

使用的环境:apache-mime4j-0.6.jar,httpcore-4.3.2.jar,httpmime-4.3.3.jar

try {
HttpPost httpPost = new HttpPost(GlobalData.urls.get("awsSub"));
MultipartEntityBuilder multipartEntityBuilder = MultipartEntityBuilder.create();
multipartEntityBuilder.addTextBody("title", "send by mobile");
multipartEntityBuilder.addTextBody("id", "");
multipartEntityBuilder.addTextBody("op", "");
multipartEntityBuilder.addTextBody("type1", "1");
multipartEntityBuilder.addTextBody("ip", "");
multipartEntityBuilder.addTextBody("admuser", "");
multipartEntityBuilder.addTextBody("admpass", "");
multipartEntityBuilder.addTextBody("ftpname", "");
multipartEntityBuilder.addTextBody("url", "");
multipartEntityBuilder.addTextBody("Body", "手机端发送滴哟 内容");
multipartEntityBuilder.addTextBody("autofix", "1");
multipartEntityBuilder.addTextBody("Submitend", "提交");
multipartEntityBuilder.addTextBody("Submit", "继续发表");
multipartEntityBuilder.addTextBody("XQtitle", "");
multipartEntityBuilder.addTextBody("theBody", "");
multipartEntityBuilder.addBinaryBody("aboutimg1", new byte[0], ContentType.MULTIPART_FORM_DATA,"");
multipartEntityBuilder.addBinaryBody("aboutimg2", new byte[0], ContentType.MULTIPART_FORM_DATA,"");
multipartEntityBuilder.addBinaryBody("aboutimg3", new byte[0], ContentType.MULTIPART_FORM_DATA,"");
multipartEntityBuilder.addBinaryBody("aboutimg4", new byte[0], ContentType.MULTIPART_FORM_DATA,"");
multipartEntityBuilder.addBinaryBody("aboutimg5", new byte[0], ContentType.MULTIPART_FORM_DATA,"");
multipartEntityBuilder.addTextBody("endtest", ""); httpPost.setEntity(multipartEntityBuilder.build());
HttpResponse httpResponse = HttpUtil.httpClient.execute(httpPost);
String txt = EntityUtils.toString(httpResponse.getEntity(),"gbk");
Intent intent = new Intent(KeFuActivity.this, ResultActivity.class);
intent.putExtra("html",txt);
startActivity(intent);
} catch (Exception e) {
e.printStackTrace();
}
上一篇:蝇量模式(Flyweight Pattern)


下一篇:Netty高性能之Reactor线程模型