栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 面试经验 > 面试问答

如何使用JSoup发布文件?

面试问答 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

如何使用JSoup发布文件?

从Jsoup 1.8.2(2015年4月13日)开始,通过新

data(String, String,InputStream)
方法才支持此功能。

String url = "http://www......com/....php";File file = new File("/path/to/file.ext");document document = Jsoup.connect(url)    .data("user", "user")    .data("password", "12345")    .data("email", "info@tutorialswindow.com")    .data("file", file.getName(), new FileInputStream(file))    .post();// ...

在旧版本中,

multipart/form-data
不支持发送请求。最好的选择是为此使用一个值得使用的HTTP客户端,例如Apache
HttpComponents Client
。最终,您可以获得HTTP客户端响应,
String
以便可以将其反馈给
Jsoup#parse()
method。

String url = "http://www......com/....php";File file = new File("/path/to/file.ext");MultipartEntity entity = new MultipartEntity();entity.addPart("user", new StringBody("user"));entity.addPart("password", new StringBody("12345"));entity.addPart("email", new StringBody("info@tutorialswindow.com"));entity.addPart("file", new InputStreamBody(new FileInputStream(file), file.getName()));HttpPost post = new HttpPost(url);post.setEntity(entity);HttpClient client = new DefaultHttpClient();HttpResponse response = client.execute(post);String html = EntityUtils.toString(response.getEntity());document document = Jsoup.parse(html, url);// ...


转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/487007.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号