public T ifError() { if (response.statusCode() >= 400) { return logResponse(LogDetail.ALL); } return (T) this; }
Connection.Response response = null; try { response = Jsoup.connect(bad_url) .userAgent("Mozilla/5.0 (Windows NT 6.0) AppleWebKit/536.5 (KHTML, like Gecko) Chrome/19.0.1084.46 Safari/536.5") .timeout(100000) .ignoreHttpErrors(true) .execute(); } catch (IOException e) { System.out.println("io - "+e); } System.out.println("Status code = " + response.statusCode()); System.out.println("Status msg = " + response.statusMessage());
public T ifStatusCodeIsEqualTo(int statusCode) { if (response.statusCode() == statusCode) { return logResponse(LogDetail.ALL); } return (T) this; }
Connection.Response response = Jsoup.connect(sitemapPath) .userAgent("Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/535.21 (KHTML, like Gecko) Chrome/19.0.1042.0 Safari/535.21") .timeout(10000) .execute(); int statusCode = response.statusCode(); if(statusCode == 200) { Document doc = connection.get(); Elements element = doc.select("loc"); for (Element urls : element) { System.out.println(urls.text()); } } else { System.out.println("received error code : " + statusCode); }
public T ifStatusCodeMatches(Matcher<Integer> matcher) { notNull(matcher, "Matcher"); if (matcher.matches(response.statusCode())) { return logResponse(LogDetail.ALL); } return (T) this; }
public Response filter(FilterableRequestSpecification requestSpec, FilterableResponseSpecification responseSpec, FilterContext ctx) { Response response = ctx.next(requestSpec, responseSpec); final int statusCode = response.statusCode(); if (matcher.matches(statusCode)) { ResponsePrinter.print(response, response, stream, logDetail, shouldPrettyPrint); final byte[] responseBody; if (logDetail == BODY || logDetail == ALL) { responseBody = response.asByteArray(); } else { responseBody = null; } response = cloneResponseIfNeeded(response, responseBody); } return response; }
@Override public int getStatus() { return response.statusCode(); }
@Override public int getStatus() { return response.statusCode(); }
Connection connection = Jsoup.connect(mArtisName).ignoreContentType(true).ignoreHttpErrors(true); Connection.Response resp = connection.execute(); Document document; if (resp.statusCode() ==200) { document = connection.parser(Parser.xmlParser()).post(); urlArtis = document.select("image[size=extralarge]").text(); }
try { Response response = Jsoup.connect("http://localhost:8080") .method(Method.POST).data("fname", "ÄÖÜ-foobar").data("lname", "äöü1234") .header("Content-Type", "application/x-www-form-urlencoded") .postDataCharset("UTF-8") .execute(); System.out.println(response.statusCode() + "\n" + response.parse().text()); } catch (IOException e) { e.printStackTrace(); }
try { Response resp = conn.execute(); if (resp.statusCode() != 200) { System.out.println("Error: "+resp.statusCode()); }else{ System.out.println(Thread.currentThread().getName()+" is downloading "+ url);
try{ Connection.Response response = Jsoup.connect("https://asdasdasd.com") .userAgent("Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/535.21 (KHTML, like Gecko) Chrome/19.0.1042.0 Safari/535.21") .timeout(10000) .ignoreHttpErrors(true). .execute(); int statusCode = response.statusCode(); if(statusCode == 200) { Document doc = Jsoup.connect("https://asdasdasd.com").get(); Elements links = doc.select("div.postdetails"); for (Element link : links) { // get the value from href attribute System.out.println("\nlink : " + link.attr("div")); System.out.println("text : " + link.text()); } } else { System.out.println("received error code : " + statusCode); } } catch (IOException e) { e.printStackTrace(); }
final String URL = "http://myagdikali.com/category/news/national-news/page/"; final int OK = 200; String currentURL; int page = 2; int status = OK; Connection.Response response = null; Document doc = null; while (status == OK) { currentURL = URL + String.valueOf(page); //add the page number to the url response = Jsoup.connect(currentURL) .userAgent("Mozilla/5.0") .execute(); //you may add here userAgent/timeout etc. status = response.statusCode(); if (status == OK) { doc = response.parse(); //extract the info. you need } page++; }
/** * 获取本次请求的响应信息 * * @param response */ private String getResponseInfo(Response response) { // TODO - 此处容易抛异常 if (response.contentType().contains("json")) { return "[" + response.statusCode() + "]" + response.jsonPath().get(); } else { return "[" + response.statusCode() + "]" + response.htmlPath().get(); } }
try { Connection.Response response = Jsoup .connect(htmlUrl) .userAgent( "Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/535.21 (KHTML, like Gecko) Chrome/19.0.1042.0 Safari/535.21") .timeout(1000000).execute(); int statusCode = response.statusCode(); Log.d("TAG", " status code is: " + statusCode); if (statusCode == 200) { doc = Jsoup.connect(htmlUrl).timeout(1000 * 1000).get(); Elements meta = doc.select("meta[property=og:video]"); for (Element src : meta) { if (src.tagName().equals("meta")) Log.d("TAG", " content: " + src.attr("content")); else Log.d("TAG", src.tagName()); } } else { System.out.println("received error code : " + statusCode); } } catch (IOException e) { Log.d("TAG", " Exception " + e); e.printStackTrace(); }
Connection.Response loginForm = Jsoup.connect("https://login.to/") .ignoreContentType(true) .userAgent("Mozilla/5.0 (Windows NT 6.1; Win64; x64; rv:25.0) Gecko/20100101 Firefox/25.0") .referrer("http://www.google.com") .timeout(12000) .followRedirects(true) .method(Connection.Method.GET) .execute(); Connection.Response loginFormFilled = Jsoup.connect("https://login.to/") .ignoreContentType(true) .userAgent("Mozilla/5.0 (Windows NT 6.1; Win64; x64; rv:25.0) Gecko/20100101 Firefox/25.0") .followRedirects(true) .referrer("https://login.to/") .data("LOGON", "user")//check the form to find field name for user name .data("PASSWORDS", "pass")//check the form to find field name for user password .cookies(loginForm.cookies()) .method(Connection.Method.POST) .execute(); int statusCode = loginFormFilled.statusCode(); Map<String, String> cookies = loginFormFilled.cookies();
@Test( groups = {MUST}, description = "LDP servers that successfully create a resource from a " + "RDF representation in the request entity body MUST honor the " + "client's requested interaction model(s). The created resource " + "can be thought of as an RDF named graph [rdf11-concepts]. If any " + "model cannot be honored, the server MUST fail the request.") @Parameters("containerAsResource") @SpecTest( specRefUri = LdpTestSuite.SPEC_URI + "#ldpc-post-createrdf", testMethod = METHOD.AUTOMATED, approval = STATUS.WG_APPROVED, comment = "Covers only part of the specification requirement. " + "testRequestedInteractionModelHeaders covers the rest.") public void testRequestedInteractionModelCreateNotAllowed(@Optional String containerAsResource) { if (containerAsResource == null) throw new SkipException(Thread.currentThread().getStackTrace()[1].getMethodName(), "containerAsResource is null", skipLog); Model model = postContent(); // If create is successful, then not acting like a plain ole resource Response postResponse = buildBaseRequestSpecification().contentType(TEXT_TURTLE) .body(model, new RdfObjectMapper()) .post(containerAsResource); // Cleanup if it actually created something String location = postResponse.getHeader(LOCATION); if (postResponse.statusCode() == HttpStatus.SC_CREATED && location !=null) buildBaseRequestSpecification().delete(location); assertNotEquals(postResponse.statusCode(), HttpStatus.SC_CREATED, "Resources with interaction model of only ldp:Resources shouldn't allow container POST-create behavior."); // TODO: Possibly parse 'Allow' header to see if POST is wrongly listed }
public boolean isServerStarted() { try { RestAssuredConfig config = RestAssured.config().httpClient(RestAssuredConfig.config().getHttpClientConfig().setParam("CONNECTION_MANAGER_TIMEOUT", 1000)); return RestAssured.given().config(config).baseUri(getBaseUri()).basePath("/mockserver").get("/").statusCode() == 200; } catch (Exception e) { return false; } }
protected Response expectPut4xxStatus(String invalidProp) { // Get the resource. String resourceUri = getResourceUri(); Response getResponse = buildBaseRequestSpecification() .expect() .statusCode(isSuccessful()) .header(ETAG, isValidEntityTag()) .when() .get(resourceUri); String eTag = getResponse.getHeader(ETAG); Model m = getResponse.as(Model.class, new RdfObjectMapper(resourceUri)); modifyProperty(m, resourceUri, invalidProp); Response putResponse = buildBaseRequestSpecification() .contentType(TEXT_TURTLE) .header(IF_MATCH, eTag) .body(m, new RdfObjectMapper(resourceUri)) .when() .put(resourceUri); if (isSuccessful().matches(putResponse.getStatusCode())) { throw new SkipException(Thread.currentThread().getStackTrace()[1].getMethodName(), "Skipping test because PUT request was successful.", skipLog); } assertThat(putResponse.statusCode(), is4xxRange()); return putResponse; }
assertEquals(Integer.parseInt(expectStatus), response.statusCode());