1. 程式人生 > >使用nutz傳送http請求

使用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();

設定代理