当前位置: 首页>>代码示例>>Java>>正文


Java HttpMethod类代码示例

本文整理汇总了Java中com.gargoylesoftware.htmlunit.HttpMethod的典型用法代码示例。如果您正苦于以下问题:Java HttpMethod类的具体用法?Java HttpMethod怎么用?Java HttpMethod使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


HttpMethod类属于com.gargoylesoftware.htmlunit包,在下文中一共展示了HttpMethod类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: login

import com.gargoylesoftware.htmlunit.HttpMethod; //导入依赖的package包/类
private static List<HtmlAnchor> login(final WebClient client)
		throws IOException, MalformedURLException, Exception {
	final HtmlPage homepage = client.getPage("http://ogame.org");

	// we use a POST because filling out the form and clicking the login button doesn't work...
	WebRequest settings = new WebRequest(new URL(
			"http://ogame.org/main/login"), HttpMethod.POST);

	settings.setRequestParameters(new ArrayList<NameValuePair>());
	settings.getRequestParameters().add(new NameValuePair("kid", ""));
	settings.getRequestParameters().add(new NameValuePair("uni", Main.settings.get("universe")));
	settings.getRequestParameters().add(new NameValuePair("login", Main.settings.get("login")));
	settings.getRequestParameters().add(new NameValuePair("pass", Main.settings.get("password")));

	page = client.getPage(settings);
	updateGame(page);

	List<HtmlAnchor> menu = (List<HtmlAnchor>)page.getByXPath("//a[contains(@class, 'menubutton')]");
	//System.out.println(menu);

	//dump(page, "game.html");
	return menu;
}
 
开发者ID:vcosta,项目名称:ogamemafia,代码行数:24,代码来源:Main.java

示例2: testFormHeaderOk

import com.gargoylesoftware.htmlunit.HttpMethod; //导入依赖的package包/类
/**
 * Checks that CSRF validation works if token sent as header instead of
 * form field.
 *
 * @throws Exception an error occurs or validation fails.
 */
@Test
public void testFormHeaderOk() throws Exception {
    HtmlPage page1 = webClient.getPage(webUrl + "resources/csrf");

    // Check response and CSRF header
    WebResponse res = page1.getWebResponse();
    assertEquals(Response.Status.OK.getStatusCode(), res.getStatusCode());
    assertNotNull(res.getResponseHeaderValue(CSRF_HEADER));

    WebRequest req = new WebRequest(new URL(webUrl + "resources/csrf"));
    req.setHttpMethod(HttpMethod.POST);
    req.setAdditionalHeader(CSRF_HEADER, res.getResponseHeaderValue(CSRF_HEADER));
    res = webClient.loadWebResponse(req);
    assertEquals(Response.Status.OK.getStatusCode(), res.getStatusCode());
}
 
开发者ID:mvc-spec,项目名称:ozark,代码行数:22,代码来源:CsrfIT.java

示例3: loginBySpecialPost

import com.gargoylesoftware.htmlunit.HttpMethod; //导入依赖的package包/类
protected RespWithTokenJSON loginBySpecialPost() throws FailingHttpStatusCodeException, IOException {
	WebRequest wr = new WebRequest(new URL(MP_WEIXIN_LOGIN), HttpMethod.POST);
	wr.getAdditionalHeaders().put("Accept", "*/*");
	wr.getAdditionalHeaders().put("Accept-Encoding", "gzip, deflate, br");
	wr.getAdditionalHeaders().put("Accept-Language", "en-US,en;q=0.5");
	wr.getAdditionalHeaders().put("Connection", "keep-alive");
	wr.getAdditionalHeaders().put("Content-Type", "application/x-www-form-urlencoded; charset=UTF-8");
	wr.getAdditionalHeaders().put("Host", "mp.weixin.qq.com");
	wr.getAdditionalHeaders().put("Referer", "https://mp.weixin.qq.com/");
	wr.getAdditionalHeaders().put("User-Agent",
			"Mozilla/5.0 (Windows NT 6.1; WOW64; rv:44.0) Gecko/20100101 Firefox/44.0");
	wr.getAdditionalHeaders().put("X-Requested-With", "XMLHttpRequest");
	List<NameValuePair> params = new ArrayList<NameValuePair>();
	params.add(new NameValuePair("f", "json"));
	params.add(new NameValuePair("imgcode", ""));
	//here password should be encrypt by MD5 and to lower case
	params.add(new NameValuePair("pwd", this.securityNP.getPass()));
	params.add(new NameValuePair("username", this.securityNP.getName()));
	wr.setRequestParameters(params);
	Page page = this.webClient.getPage(wr);
	String respJson = page.getWebResponse().getContentAsString();
	return RespWithTokenJSON.fromJson(respJson);
}
 
开发者ID:alexmao86,项目名称:weixinmp4j,代码行数:24,代码来源:WeixinmpWebSession.java

示例4: getAccessToken

import com.gargoylesoftware.htmlunit.HttpMethod; //导入依赖的package包/类
private OAuthToken getAccessToken(String refreshToken) throws IOException {
    final String tokenUrl = String.format(ACCESS_TOKEN_URL, refreshToken,
        oAuthParams.getRedirectUri(), oAuthParams.getClientId(), oAuthParams.getClientSecret());
    final WebRequest webRequest = new WebRequest(new URL(tokenUrl), HttpMethod.POST);

    final WebResponse webResponse = webClient.loadWebResponse(webRequest);
    if (webResponse.getStatusCode() != HttpStatus.SC_OK) {
        throw new IOException(String.format("Error getting access token: [%s: %s]",
            webResponse.getStatusCode(), webResponse.getStatusMessage()));
    }
    final long currentTime = System.currentTimeMillis();
    final ObjectMapper mapper = new ObjectMapper();
    final Map map = mapper.readValue(webResponse.getContentAsStream(), Map.class);
    final String accessToken = map.get("access_token").toString();
    final Integer expiresIn = Integer.valueOf(map.get("expires_in").toString());
    return new OAuthToken(refreshToken, accessToken,
        currentTime + TimeUnit.MILLISECONDS.convert(expiresIn, TimeUnit.SECONDS));
}
 
开发者ID:HydAu,项目名称:Camel,代码行数:19,代码来源:LinkedInOAuthRequestFilter.java

示例5: setTicketFieldValue

import com.gargoylesoftware.htmlunit.HttpMethod; //导入依赖的package包/类
private void setTicketFieldValue(final GepardTestClass tc, final String ticket, final String fieldName, final String value) throws IOException {
    String jiraSetFieldPage = getIssueFieldSetValueUrl(ticket);
    WebRequest requestSettings = new WebRequest(new URL(jiraSetFieldPage), HttpMethod.PUT);
    requestSettings.setAdditionalHeader("Content-type", "application/json");
    requestSettings.setRequestBody("{ \"fields\": {\"" + fieldName + "\": \"" + value + "\"} }");
    try {
        UnexpectedPage infoPage = webClient.getPage(requestSettings);
        if (infoPage.getWebResponse().getStatusCode() == HTTP_RESPONSE_OK) {
            tc.logComment("Field: '" + fieldName + "' of Ticket: " + ticket + " was updated to value: '" + value + "' successfully.");
        } else {
            throw new SimpleGepardException("Ticket: " + ticket + " field: " + fieldName + " update failed, status code: " + infoPage.getWebResponse().getStatusCode());
        }
    } catch (FailingHttpStatusCodeException e) {
        throw new SimpleGepardException("Ticket: " + ticket + " field: " + fieldName + " update failed.", e);
    }
}
 
开发者ID:epam,项目名称:Gepard,代码行数:17,代码来源:JiraSiteHandler.java

示例6: collectIssues

import com.gargoylesoftware.htmlunit.HttpMethod; //导入依赖的package包/类
/**
 * Get a Jira query result in a map form.
 *
 * @param query is the jira query
 * @return with the map of JIRA_ID - ticketInfo in JSONObject pairs as result of a Jira query.
 * @throws IOException   in case of problem
 * @throws JSONException in case of problem
 */
public ConcurrentHashMap<String, JSONObject> collectIssues(final String query) throws IOException, JSONException {
    String jqlURL = getListOfIssuesByQueryUrl(query);
    WebRequest requestSettings = new WebRequest(new URL(jqlURL), HttpMethod.GET);
    requestSettings.setAdditionalHeader("Content-type", "application/json");
    UnexpectedPage infoPage = webClient.getPage(requestSettings);
    if (infoPage.getWebResponse().getStatusCode() == HTTP_RESPONSE_OK) {
        String ticketList = infoPage.getWebResponse().getContentAsString();
        JSONObject obj = new JSONObject(ticketList);
        String maxResults = obj.getString("maxResults");
        String total = obj.getString("total");
        if (Integer.valueOf(maxResults) < Integer.valueOf(total)) {
            throw new SimpleGepardException("ERROR: Too many issues belong to given query (" + total + "), please change the query to shorten the result list.");
        }
        JSONArray array = obj.getJSONArray("issues");
        ConcurrentHashMap<String, JSONObject> map = new ConcurrentHashMap<>();
        for (int i = 0; i < array.length(); i++) {
            JSONObject o = (JSONObject) array.get(i);
            map.put(o.getString("key"), o);
        }
        return map;
    }
    throw new SimpleGepardException("ERROR: Cannot fetch Issue list from JIRA, status code:" + infoPage.getWebResponse().getStatusCode());
}
 
开发者ID:epam,项目名称:Gepard,代码行数:32,代码来源:JiraSiteHandler.java

示例7: transferTicketToStatus

import com.gargoylesoftware.htmlunit.HttpMethod; //导入依赖的package包/类
/**
 * Transition a ticket to next status in its workflow.
 * URL --> https://jira.xxxxxx.com/rest/api/2/issue/TEST-53/transitions?expand=transitions.fields
 * POST data --> {"transition":{"id":91}}
 * Returned HTTP response --> 204
 *
 * @param ticket             is the specific ticket
 * @param statusTransferId   is the id of the transaction that should be used to transfer the ticket
 * @param expectedStatusName is the name of the expected new status
 * @param comment            that will be attached to the ticket as comment of the transaction
 * @return with the new status
 */
private String transferTicketToStatus(final GepardTestClass tc, final String ticket, final String statusTransferId, final String expectedStatusName, final String comment)
        throws IOException, JSONException {
    String updateString = "{ \"update\": { \"comment\": [ { \"add\": { \"body\": \"" + comment + "\" } } ] }, \"transition\": { \"id\": \"" + statusTransferId + "\" } }";
    String oldStatus = detectActualStatus(ticket);
    String newStatus;
    String jiraSetFieldPage = getIssueSetTransitionsUrl(ticket);
    WebRequest requestSettings = new WebRequest(new URL(jiraSetFieldPage), HttpMethod.POST);
    requestSettings.setAdditionalHeader("Content-type", "application/json");
    requestSettings.setRequestBody(updateString);
    try {
        UnexpectedPage infoPage = webClient.getPage(requestSettings);
        if (infoPage.getWebResponse().getStatusCode() == HTTP_RESPONSE_OK) {
            newStatus = detectActualStatus(ticket);
            Assert.assertEquals("Transferring ticket: " + ticket + " to new status failed,", expectedStatusName, newStatus);
            tc.logComment("Ticket: " + ticket + " was transferred from status: \"" + oldStatus + "\" to status: \"" + newStatus + "\" successfully.");
        } else {
            throw new SimpleGepardException("ERROR: Status update failed for ticket: " + ticket + ", Status code:" + infoPage.getWebResponse().getStatusCode());
        }
    } catch (FailingHttpStatusCodeException e) {
        throw new SimpleGepardException("ERROR: Status update failed for ticket: " + ticket + ".", e);
    }
    return newStatus;
}
 
开发者ID:epam,项目名称:Gepard,代码行数:36,代码来源:JiraSiteHandler.java

示例8: putCustomListsTest

import com.gargoylesoftware.htmlunit.HttpMethod; //导入依赖的package包/类
@Test(enabled = false, dataProvider = Arquillian.ARQUILLIAN_DATA_PROVIDER, priority = 2)
@OperateOnDeployment("ear")
@RunAsClient
public void putCustomListsTest(@ArquillianResource URL context) throws Exception {
    WebClient webClient = new WebClient();
    WebRequest requestSettings = new WebRequest(new URL(context + "rest/lists/2"), HttpMethod.PUT);
    requestSettings.setAdditionalHeader("Content-Type", "application/json");
    requestSettings.setAdditionalHeader("X-sinkit-token", TOKEN);
    requestSettings.setRequestBody(
            "[{\"dns_client\":\"10.10.10.10/32\"," +
                    "\"lists\":{\"seznam.cz\":\"W\"," +
                    "\"google.com\":\"B\"," +
                    "\"example.com\":\"L\"}" +
                    "}," +
                    "{\"dns_client\":\"fe80::3ea9:f4ff:fe81:c450/64\"," +
                    "\"lists\":{\"seznam.cz\":\"L\"," +
                    "\"google.com\":\"W\"," +
                    "\"example.com\":\"W\"}" +
                    "}]");
    Page page = webClient.getPage(requestSettings);
    assertEquals(HttpURLConnection.HTTP_OK, page.getWebResponse().getStatusCode());
    String responseBody = page.getWebResponse().getContentAsString();
    LOGGER.info("putCustomListsTest Response:" + responseBody);
    String expected = "6 CUSTOM LISTS ELEMENTS PROCESSED, 6 PRESENT";
    assertTrue(responseBody.contains(expected), "Expected: " + expected + ", but got: " + responseBody);
}
 
开发者ID:whalebone,项目名称:sinkit-core,代码行数:27,代码来源:ApiIntegrationTest.java

示例9: getIoCTest

import com.gargoylesoftware.htmlunit.HttpMethod; //导入依赖的package包/类
@Test(enabled = false, dataProvider = Arquillian.ARQUILLIAN_DATA_PROVIDER, priority = 6)
@OperateOnDeployment("ear")
@RunAsClient
public void getIoCTest(@ArquillianResource URL context) throws Exception {
    WebClient webClient = new WebClient();
    WebRequest requestSettings = new WebRequest(new URL(context + "rest/blacklist/record/seznam.cz"), HttpMethod.GET);
    requestSettings.setAdditionalHeader("Content-Type", "application/json");
    requestSettings.setAdditionalHeader("X-sinkit-token", TOKEN);
    Page page = webClient.getPage(requestSettings);
    assertEquals(HttpURLConnection.HTTP_OK, page.getWebResponse().getStatusCode());
    String responseBody = page.getWebResponse().getContentAsString();
    LOGGER.info("getIoCTest Response:" + responseBody);
    String expected = "\"black_listed_domain_or_i_p\":\"aed14ad7ed6c543f818a4cfe89cb8f20\""; // md5 of seznam.cz
    assertTrue(responseBody.contains(expected), "IoC response should have contained " + expected + ", but got:" + responseBody);
    expected = "\"sources\":{\"feed2\":{\"a\":\"blacklist\",\"b\":\"myDocumentId\"}}";
    assertTrue(responseBody.contains(expected), "IoC should have contained " + expected + ", but got: " + responseBody);
}
 
开发者ID:whalebone,项目名称:sinkit-core,代码行数:18,代码来源:ApiIntegrationTest.java

示例10: cleanElasticTest

import com.gargoylesoftware.htmlunit.HttpMethod; //导入依赖的package包/类
/**
 * Not test exactly, just cleaning old data in elastic
 *
 * @param context
 * @throws Exception
 */

@Test(enabled = false, dataProvider = Arquillian.ARQUILLIAN_DATA_PROVIDER, priority = 8)
@OperateOnDeployment("ear")
@RunAsClient
public void cleanElasticTest(@ArquillianResource URL context) throws Exception {
    WebClient webClient = new WebClient();
    WebRequest requestSettings = new WebRequest(
            new URL("http://" + System.getenv("SINKIT_ELASTIC_HOST") + ":" + System.getenv("SINKIT_ELASTIC_PORT") +
                    "/" + ArchiveServiceEJB.ELASTIC_IOC_INDEX + "/"), HttpMethod.DELETE);
    Page page;
    try {
        page = webClient.getPage(requestSettings);
        assertEquals(HttpURLConnection.HTTP_OK, page.getWebResponse().getStatusCode());
    } catch (FailingHttpStatusCodeException ex) {
        //NO-OP index does not exist yet, but it's ok
    }
}
 
开发者ID:whalebone,项目名称:sinkit-core,代码行数:24,代码来源:ApiIntegrationTest.java

示例11: iocInCacheTest

import com.gargoylesoftware.htmlunit.HttpMethod; //导入依赖的package包/类
@Test(enabled = false, dataProvider = Arquillian.ARQUILLIAN_DATA_PROVIDER, priority = 11)
@OperateOnDeployment("ear")
@RunAsClient
public void iocInCacheTest(@ArquillianResource URL context) throws Exception {
    WebClient webClient = new WebClient();
    WebRequest requestSettings = new WebRequest(new URL(context + "rest/blacklist/record/phishing.ru"), HttpMethod.GET);
    requestSettings.setAdditionalHeader("Content-Type", "application/json");
    requestSettings.setAdditionalHeader("X-sinkit-token", TOKEN);
    Page page = webClient.getPage(requestSettings);
    assertEquals(HttpURLConnection.HTTP_OK, page.getWebResponse().getStatusCode());
    String responseBody = page.getWebResponse().getContentAsString();
    LOGGER.info("iocInCacheTest Response:" + responseBody);
    String expected = "\"black_listed_domain_or_i_p\":\"926dab5157943daed27851a34f30b701\"";  // md5 of phishing.ru
    assertTrue(responseBody.contains(expected), "IoC response should have contained " + expected + ", but got:" + responseBody);
    expected = "\"sources\":{\"integrationTest\":{\"a\":\"phishing\",\"b\":\"";
    assertTrue(responseBody.contains(expected), "IoC should have contained " + expected + ", but got: " + responseBody);
}
 
开发者ID:whalebone,项目名称:sinkit-core,代码行数:18,代码来源:ApiIntegrationTest.java

示例12: cleanElasticTest

import com.gargoylesoftware.htmlunit.HttpMethod; //导入依赖的package包/类
/**
 * Not test exactly, just cleaning old data in elastic DNS event logs
 *
 * @param context
 * @throws Exception
 */
@Test(enabled = false, dataProvider = Arquillian.ARQUILLIAN_DATA_PROVIDER, priority = 17)
@OperateOnDeployment("ear")
@RunAsClient
public void cleanElasticTest(@ArquillianResource URL context) throws Exception {

    String index = IoCFactory.getLogIndex();

    WebClient webClient = new WebClient();
    WebRequest requestSettings = new WebRequest(
            new URL("http://" + System.getenv("SINKIT_ELASTIC_HOST") + ":" + System.getenv("SINKIT_ELASTIC_PORT") +
                    "/" + index + "/"), HttpMethod.DELETE);
    Page page;
    try {
        page = webClient.getPage(requestSettings);
        assertEquals(HttpURLConnection.HTTP_OK, page.getWebResponse().getStatusCode());
    } catch (FailingHttpStatusCodeException ex) {
        //NO-OP index does not exist yet, but it's ok
    }
}
 
开发者ID:whalebone,项目名称:sinkit-core,代码行数:26,代码来源:CoreTest.java

示例13: enableDisabledResourceDefByRESTCall_Constructor

import com.gargoylesoftware.htmlunit.HttpMethod; //导入依赖的package包/类
/**
 * A disabled default validation at resource definition level can be enabled
 * via {@link RESTCall#RESTCall(Class, boolean)}.
 * 
 * @throws Throwable
 */
@Test
public void enableDisabledResourceDefByRESTCall_Constructor() throws Throwable
{
    // Set a default HTTP method via global properties
    XltProperties.getInstance().setProperty( GLOB_PROP_HTTP_METHOD, "PATCH" );
    
    RESTCall call = new RESTCall( DefaultValidation_Disabled.class, true ).setDefinitionClass(
            DefaultValidation_Disabled2nd.class ).setPreviousAction( mockAction );

    assertTrue( "Default validation should be enabled by default.", call.isDefaultValidationEnabled() );
    assertEquals( HttpMethod.PATCH, call.getHttpMethod() );

    call.process();

    assertTrue( "DefaultValidation_Disabled: not performed.", DefaultValidation_Disabled.valPerformed );
    assertFalse( "DefaultValidation_Disabled2nd: performed.", DefaultValidation_Disabled2nd.valPerformed );
}
 
开发者ID:Xceptance,项目名称:XRT-Xceptance-REST-Test,代码行数:24,代码来源:TestDefaultValidation.java

示例14: testStatefulRequests

import com.gargoylesoftware.htmlunit.HttpMethod; //导入依赖的package包/类
@Test
public void testStatefulRequests() throws Exception {
    
    server.handle(Method.PUT, "/name/:name")
          .with(200, "text/plain", "OK")
          .withSessionHandler(new PathParamSessionHandler());
    
    server.handle(Method.GET, "/name")
          .with(200, "text/plain", "Name: {name}");
    
    WebClient client = new WebClient();
    
    Page page = client.getPage(new WebRequest(new URL(
            "http://localhost:8080/name/Tim"), 
            HttpMethod.PUT));
    assertEquals(200, page.getWebResponse().getStatusCode());
    
    page      = client.getPage(new WebRequest(new URL(
            "http://localhost:8080/name"), 
            HttpMethod.GET));
    assertEquals("Name: Tim", page.getWebResponse().getContentAsString().trim());
}
 
开发者ID:lantunes,项目名称:fixd,代码行数:23,代码来源:TestServerFixture.java

示例15: testStatefulRequestsUsingRequestParams

import com.gargoylesoftware.htmlunit.HttpMethod; //导入依赖的package包/类
@Test
public void testStatefulRequestsUsingRequestParams() throws Exception {
    
    server.handle(Method.POST, "/", "application/x-www-form-urlencoded")
          .with(200, "text/plain", "OK")
          .withSessionHandler(new RequestParamSessionHandler());
    
    server.handle(Method.GET, "/")
          .with(200, "text/plain", "Name: {name}");
    
    WebClient client = new WebClient();
    
    Page page = client.getPage(new WebRequest(new URL(
            "http://localhost:8080/?name=Tim"), 
            HttpMethod.POST));
    assertEquals(200, page.getWebResponse().getStatusCode());
    
    page      = client.getPage(new WebRequest(new URL(
            "http://localhost:8080/"), 
            HttpMethod.GET));
    assertEquals("Name: Tim", page.getWebResponse().getContentAsString().trim());
}
 
开发者ID:lantunes,项目名称:fixd,代码行数:23,代码来源:TestServerFixture.java


注:本文中的com.gargoylesoftware.htmlunit.HttpMethod类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。