如何使用httpclient4,通过cookie传递参数

2025-04-30 05:56:47
推荐回答(1个)
回答1:

直接写即可,这是我的一段代码

public static void main(String[] args) {
HTTPClient curl=new HTTPClient("");
// HTTPClient curl=new HTTPClient("");
// System.out.println(curl.doGet());
RequestHeaders headers =curl.getHeaders();
headers.setReferer("/");
headers.setHost("typecho.org");
headers.setHeader("Cookie", "PHPSESSID=e1724452dbcf2fac7e1102140d0c0fb4");
// System.out.println(headers.getHeaders().get("Content-Length"));
// Map params = new HashMap();
// params.put("author", "测试");
// params.put("mail", "");
// params.put("text", "test22");
curl.setQueryString("author=%E6%B5%8B%E8%AF%95&mail=lajitest@125.com&url=&text=typecho+%E5%BE%88%E5%A5%BD");
System.out.println(curl.doPost(false));
// for (int i = 0; i < 200; i++) {
// curl.doPost(true);
// try {
// Thread.sleep(1000);
// } catch (InterruptedException e) {
// }
// }