httoclient类中的postmethod方法中用需要传入的参数是什么?

如题所述

第1个回答  2022-11-16
  用PostMethod 模拟http post请求,需要解决传递字符串,文件等需求。\x0d\x0a  httpclient对此,提供了对应实现,实现方法关键在:RequestEntity。\x0d\x0a  示例:\x0d\x0a  RequestEntity requestEntity = newStringRequestEntity(text);\x0d\x0a  post.setRequestEntity(requestEntity);\x0d\x0a  示例中,是传递一个普通字符型参数。\x0d\x0a  这个方法代替了以前直接设置Request body。\x0d\x0a  RequestEntity是一个接口,有很多实现:  ByteArrayRequestEntity, FileRequestEntity, InputStreamRequestEntity, MultipartRequestEntity, StringRequestEntity\x0d\x0a  基本上从名字上就可以直接看出功能,可以从字符串,流,文件,字节数组中产生request body。\x0d\x0a  还有更复杂的Multipart,就是夹杂文件和普通字段的提交。\x0d\x0a  示例如下:  Part[] parts = {new StringPart("source", "695132533"), new StringPart("status", URLEncoder.encode(status, "utf-8")), filePart};  postMethod.setRequestEntity(new MultipartRequestEntity(parts, postMethod.getParams()));

相关了解……

你可能感兴趣的内容

本站内容来自于网友发表,不代表本站立场,仅表示其个人看法,不对其真实性、正确性、有效性作任何的担保
相关事宜请发邮件给我们
© 非常风气网