使用nutz发送http请求

提交json 携带cookie

private static Cookie cookie =null;

Request req =Request.create(IP+path, METHOD.POST);
		Header header = Header.create();
		header.set("Content-Type", "application/json; charset=utf-8");
		req.setHeader(header);
req.setData(Json.toJson(map, JsonFormat.compact()));
if(cookie!=null){
			req.setCookie(cookie);
		}
Response response = Sender.create(req).setTimeout(10000).send();
cookie=response.getCookie();

普通post提交

Request req =Request.create(url, METHOD.POST);
				req.getParams().put("task_id", session.getAttribute("pc_task_id"));
				req.getParams().put("capchar", customerForm.getName());
Response response = Sender.create(req).send();

设置代理


猜你喜欢

转载自blog.csdn.net/lyl117363/article/details/84785303