@Override public String execute() { Map<String, Object> resMap = new HashMap<>(); try { Connection.Response response = connection.execute(); resMap.put("code", response.statusCode()); resMap.put("message", response.statusMessage()); resMap.put("body", response.body()); } catch (IOException e) { e.printStackTrace(); resMap.put("code", "-1"); resMap.put("message", "Request Exception"); resMap.put("body", ""); } return gson.toJson(resMap); }
public Connection.Response getResponse() { if (response == null && !request.equals(EMPTY_REQUEST)) { log.debug( "Sending request, to url: {}, with headers: {}", getRequest().url(), getRequest().headers() ); response = responseSupplier.get(); log.debug("Got response, status code: {}, headers: {}", response.statusCode(), response.headers()); } return response; }
System.out.println("======================"); System.out.println(res.url()); System.out.println(res.statusCode()); System.out.println(cookies2); System.out.println(login.statusCode());
if (post.statusCode() != 302) { int index = post.body().indexOf("sErrTxt:'"); int end;
.followRedirects(false) .execute(); if(captchaResponse.statusCode() == 302 && captchaResponse.hasHeader("Location")){ Map<String, String> cookies = getCookies(cookieFileName); Response abuseResponse = getConnection(captchaResponse.header("Location"))
private String getToken(String token, String scope) throws IOException { Response response = Jsoup.connect(SERVER_HOSTNAME + "/oauth20_token.srf").data("client_id", "00000000480BC46C", "scope", scope, "grant_type", "refresh_token", "refresh_token", token).maxBodySize(100 * 1024 * 1024).timeout(10000).method(Method.POST).ignoreContentType(true).ignoreHttpErrors(true).execute(); if (response.statusCode() != 200) { try { JSONObject json = new JSONObject(response.body()); String errorDescription = json.getString("error_description"); IOException ex = new IOException("Error while connecting to Live: token request error: " + errorDescription); logger.log(Level.SEVERE, "", ex); throw ex; } catch (JSONException | IllegalFormatException e) { IOException ex = new IOException("Error while connecting to Live: unknown token request error: " + response.body()); logger.log(Level.SEVERE, "", ex); throw ex; } } try { JSONObject json = new JSONObject(response.body()); String accessToken = json.getString("access_token"); return accessToken; } catch (JSONException | IllegalFormatException e) { IOException ex = new IOException("Error while connecting to Live: failed reading token response: " + response.body()); logger.log(Level.SEVERE, "", ex); throw ex; } }
public static void main(String[] args) throws IOException { try { String url = "https://www.oschina.net/home/login"; String userAgent = "Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/43.0.2357.130 Safari/537.36"; Connection.Response response = Jsoup.connect(url).userAgent(userAgent).method(Connection.Method.GET) .execute(); response = Jsoup.connect(url).cookies(response.cookies()).userAgent(userAgent) .referrer("https://www.oschina.net/home/login?goto_page=https%3A%2F%2Fmy.oschina.net%2Fbluetata") .data("username", "dietime1943@hotmail.com", "password", "lvmeng152300").data("save_login", "1") .followRedirects(false) .method(Connection.Method.POST).followRedirects(true).timeout(30 * 1000).execute(); System.err.println(response.statusCode()); Document doc = Jsoup.connect("https://my.oschina.net/bluetata").cookies(response.cookies()) .userAgent(userAgent).timeout(30 * 1000).get(); System.out.println(doc); } catch (IOException e) { e.printStackTrace(); } }
public int getStatusCode() { return getResponse().statusCode(); }