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


Java HttpMethod.POST属性代码示例

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


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

示例1: login

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,代码行数:23,代码来源:Main.java

示例2: loginBySpecialPost

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,代码行数:23,代码来源:WeixinmpWebSession.java

示例3: getAccessToken

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,代码行数:18,代码来源:LinkedInOAuthRequestFilter.java

示例4: transferTicketToStatus

/**
 * 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,代码行数:35,代码来源:JiraSiteHandler.java

示例5: cancelBooking

public void cancelBooking( User user, Meeting meeting ) throws Exception
{
    final WebClient webClient = new WebClient();
    addCredentials( user, webClient );

    String uri = CANCEL_BOOKING + "/" + meeting.getMeetingId();
    String pageUrl = new StringBuilder( "http://" ).append( WEBSITE ).append( uri ).toString();

    URL url = new URL( pageUrl );
    WebRequest requestSettings = new WebRequest( url, HttpMethod.POST );

    Page redirectPage = webClient.getPage( requestSettings );
    logger.debug( "Confirmed Cancellation " + redirectPage.getWebResponse().getContentAsString() );
}
 
开发者ID:Vedang18,项目名称:ProBOT,代码行数:14,代码来源:Bookie.java

示例6: createRequest

protected WebRequest createRequest(String requestUrl, Map<String, String> addtionalHeaders,
		List<NameValuePair> params) throws MalformedURLException {
	WebRequest wr = new WebRequest(new URL(requestUrl), HttpMethod.POST);
	wr.getAdditionalHeaders().putAll(addtionalHeaders);
	wr.setRequestParameters(params);
	return wr;
}
 
开发者ID:alexmao86,项目名称:weixinmp4j,代码行数:7,代码来源:WeixinmpHttpRequest.java

示例7: testGetToken

public void testGetToken() throws FailingHttpStatusCodeException, IOException {
	WebClient wc = weiWS.getInstance();
	WebRequest wr = new WebRequest(new URL("https://mp.weixin.qq.com/cgi-bin/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-Length", "86");
	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", ""));
	//3BCEBC34A480F472E27372F9DE2D5592
	params.add(new NameValuePair("pwd", "3bcebc34a480f472e27372f9de2d5592"));
	params.add(new NameValuePair("username", "[email protected]"));
	wr.setRequestParameters(params);
	Page page = wc.getPage(wr);
	String response = page.getWebResponse().getContentAsString();
	System.out.println(response);
	Set<Cookie> cookies = weiWS.getInstance().getCookieManager().getCookies();
	for (Cookie cookie : cookies) {
		System.out.println(cookie.toString());
	}

	Gson gson = new Gson();
	RespWithTokenJSON jsonObj = gson.fromJson(response, RespWithTokenJSON.class);
	String homePath = jsonObj.getRedirect_url();

	HtmlPage homePage = wc.getPage("https://mp.weixin.qq.com/" + homePath);
	HtmlAnchor logout = (HtmlAnchor) homePage.getElementById("logout");
	System.out.println(logout);
	HtmlPage loginPage = wc.getPage("https://mp.weixin.qq.com");
	System.out.println(loginPage.getUrl());
}
 
开发者ID:alexmao86,项目名称:weixinmp4j,代码行数:39,代码来源:WeixinmpWebSessionTest.java

示例8: httpMethodDefinition

/**
 * Calls the constructor that takes a class with definition annotations as
 * an argument. The class defines the base Url and the base path via the
 * resource definition. The base path has a leading and a trailing '/'
 * character.
 */
@Test
public void httpMethodDefinition()
{
    // Define the resource definition
    @HttpMethodDefinition( HttpMethod.POST )
    class DefinitionClass
    {
    }

    RESTCall call = new RESTCall( DefinitionClass.class );

    Assert.assertEquals( "Expected Http Method: ", HttpMethod.POST, call.getHttpMethod() );
}
 
开发者ID:Xceptance,项目名称:XRT-Xceptance-REST-Test,代码行数:19,代码来源:TestRESTCallDefinitionSetup.java

示例9: openWithoutLogin

public static LoginPage<DrawPage> openWithoutLogin(WebClient webClient, URL url, LocalDate parse) throws IOException {
    WebRequest request = new WebRequest(new URL(url.toString() + "/draw"), HttpMethod.POST);
    List<NameValuePair> parameters = new ArrayList<>();
    parameters.add(new NameValuePair("date", "2015-01-01"));
    request.setRequestParameters(parameters);
    return new LoginPage<>(webClient.getPage(request), DrawPage.class);
}
 
开发者ID:ahus1,项目名称:keycloak-dropwizard-integration,代码行数:7,代码来源:DrawPage.java

示例10: getHTMLPageWithPost

public static Document getHTMLPageWithPost(String url, ArrayList<NameValuePair> post) throws Exception {
    Exception ex = null;

    for (int i = 0; i < NUMBER_OF_TRIES; i++) {
        try (WebClient webClient = createWebClient(url)) {
            WebRequest requestSettings = new WebRequest(new URL(url), HttpMethod.POST);

            requestSettings.setRequestParameters(new ArrayList<NameValuePair>());
            requestSettings.getRequestParameters().addAll(post);

            HtmlPage page = webClient.getPage(requestSettings);

            JavaScriptJobManager manager = page.getEnclosingWindow().getJobManager();
            while (manager.getJobCount() > 0) {
                Thread.sleep(500);
            }

            return Jsoup.parse(((HtmlPage) webClient.getCurrentWindow().getEnclosedPage()).asXml());
        } catch (Exception e) {
            System.err.println("Try " + (i + 1) + " of " + NUMBER_OF_TRIES
                    + ". Link: " + url + ". Error: " + e.getMessage());

            ex = e;
        }
    }

    throw ex;
}
 
开发者ID:hurik,项目名称:MangaManagerAndDownloader,代码行数:28,代码来源:HTMLUnitHelper.java

示例11: testPostWithCorrectCredentials

@Test
public void testPostWithCorrectCredentials() throws Exception {
    webClient.setCredentialsProvider(correctCreds);
    WebRequest request = new WebRequest(new URL(base + "/SecureServlet"), HttpMethod.POST);
    TextPage page = webClient.getPage(request);
    assertEquals("my POST", page.getContent());
}
 
开发者ID:ftomassetti,项目名称:JavaIncrementalParser,代码行数:7,代码来源:SecureServletTest.java

示例12: testPostWithIncorrectCredentials

@Test
public void testPostWithIncorrectCredentials() throws Exception {
    webClient.setCredentialsProvider(incorrectCreds);
    WebRequest request = new WebRequest(new URL(base + "/SecureServlet"), HttpMethod.POST);
    try {
        webClient.getPage(request);
    } catch(FailingHttpStatusCodeException e) {
        assertNotNull(e);
        assertEquals(401, e.getStatusCode());
        return;
    }
    fail("/SecureServlet could be accessed without proper security credentials");
}
 
开发者ID:ftomassetti,项目名称:JavaIncrementalParser,代码行数:13,代码来源:SecureServletTest.java

示例13: testPost

@Test
public void testPost() throws IOException, SAXException {
    WebRequest request = new WebRequest(new URL(base + "/TestServlet"), HttpMethod.POST);
    TextPage page = webClient.getPage(request);
    assertEquals("my POST", page.getContent());
}
 
开发者ID:ftomassetti,项目名称:JavaIncrementalParser,代码行数:6,代码来源:TestServletTest.java

示例14: testMyServlet

@Test
public void testMyServlet() throws IOException, ServletException {
    SimpleServletServer server = new SimpleServletServer();
    server.start();
    WebClient webClient = new WebClient();
    TextPage page = webClient.getPage(BASE + "/MyServlet");
    assertEquals("Hello World from GET", page.getContent());
    
    WebRequest request = new WebRequest(new URL(BASE + "/MyServlet"), HttpMethod.POST);
    page = webClient.getPage(request);
    assertEquals("Hello World from POST", page.getContent());
    server.stop();
}
 
开发者ID:arun-gupta,项目名称:wildfly-samples,代码行数:13,代码来源:SimpleServletServerTest.java

示例15: testMyAnotherServlet

@Test
public void testMyAnotherServlet() throws IOException, ServletException {
    SimpleServletServer server = new SimpleServletServer();
    server.start();
    WebClient webClient = new WebClient();
    TextPage page = webClient.getPage(BASE + "/MyAnotherServlet");
    assertEquals("Howdy World from GET", page.getContent());
    
    WebRequest request = new WebRequest(new URL(BASE + "/MyAnotherServlet"), HttpMethod.POST);
    page = webClient.getPage(request);
    assertEquals("Howdy World from POST", page.getContent());
    server.stop();
}
 
开发者ID:arun-gupta,项目名称:wildfly-samples,代码行数:13,代码来源:SimpleServletServerTest.java


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