httppost,httpget,アナログログイン操作

1756 ワード

CookieStore cookieStore = WebDriverUtil.seleniumCookiesToCookieStore(driver);
		
		CloseableHttpClient client = HttpClients.custom()
		        .setDefaultCookieStore(cookieStore).build();
		
		HttpGet httpGet = new HttpGet(url);
		try {
	      //  get 
	      HttpResponse httpResponse = client.execute(httpGet);
	      String responseStr = EntityUtils.toString(httpResponse.getEntity());
	      JSONObject jsonObject = JSONObject.fromObject(responseStr);
	      String data = jsonObject.getString("data");
	      
	    }

 
HttpPost httppost = new HttpPost(url);
			httppost.setHeader("Accept", "application/json, text/javascript, */*; q=0.01");
			httppost.setHeader("Accept-Encoding", "gzip, deflate");
			httppost.setHeader("Accept-Language", "zh-CN,zh;q=0.8,en-US;q=0.5,en;q=0.3");
			httppost.setHeader("Host", "www.baidu.com");
			httppost.setHeader("User-Agent",
					"Mozilla/5.0 (Windows NT 6.1; WOW64; rv:42.0) Gecko/20100101 Firefox/42.0");
			httppost.setHeader("X-Requested-With", "XMLHttpRequest");
			httppost.setHeader("Content-Type", "application/json; charset=utf-8");
			httppost.setHeader("Cookie", stringCookie);

			StringEntity se = new StringEntity("{beginDate: \"" + date + "\", day: 1}", Consts.UTF_8);
			se.setContentType("application/json;charset=UTF-8");
			httppost.setEntity(se);

			
			CloseableHttpResponse response = httpclient.execute(httppost);
			if (response.getStatusLine().getStatusCode() != 200) {
				System.out.println("http ");
				result.setSuccess(false);
				return result;
			}