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


Java NameValuePair类代码示例

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


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

示例1: login

import com.gargoylesoftware.htmlunit.util.NameValuePair; //导入依赖的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: params

import com.gargoylesoftware.htmlunit.util.NameValuePair; //导入依赖的package包/类
private void params(MockHttpServletRequest request, UriComponents uriComponents) {
	for (Entry<String, List<String>> entry : uriComponents.getQueryParams().entrySet()) {
		String name = entry.getKey();
		for (String value : entry.getValue()) {
			try {
				value = (value != null ? URLDecoder.decode(value, "UTF-8") : "");
				request.addParameter(name, value);
			}
			catch (UnsupportedEncodingException e) {
				throw new RuntimeException(e);
			}
		}
	}
	for (NameValuePair param : this.webRequest.getRequestParameters()) {
		request.addParameter(param.getName(), param.getValue());
	}
}
 
开发者ID:langtianya,项目名称:spring4-understanding,代码行数:18,代码来源:HtmlUnitRequestBuilder.java

示例3: execute

import com.gargoylesoftware.htmlunit.util.NameValuePair; //导入依赖的package包/类
/**
 * {@inheritDoc}
 */
@Override
public void execute(Context context)
{
	LoggerFactory.getLogger(Request.class).debug("Executing action: " + this);
	try
	{
		WebRequest webRequest = new WebRequest(UrlUtils.toUrlUnsafe(Util.replacePlaceholders(url, context)), method);
		List<NameValuePair> replacedParams = new ArrayList<>();
		params.forEach(param -> replacedParams.add(new NameValuePair(param.getName(), param.getValue())));
		webRequest.setRequestParameters(replacedParams);
		if(credentials != null)
			webRequest.setCredentials(new UsernamePasswordCredentials(credentials.getName(), credentials.getValue()));
		context.getWebClient().getPage(webRequest);
	}
	catch(IOException e)
	{
		throw new RuntimeException(e);
	}
}
 
开发者ID:sropelato,项目名称:Fetchino,代码行数:23,代码来源:Request.java

示例4: loginBySpecialPost

import com.gargoylesoftware.htmlunit.util.NameValuePair; //导入依赖的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

示例5: setUp

import com.gargoylesoftware.htmlunit.util.NameValuePair; //导入依赖的package包/类
/**
 * Test setup. Creates the mocked action that needs to be used in every test
 * as previous action.
 * 
 * @throws Throwable
 */
@Before
public void setUp() throws Throwable
{
    // Adding HTTP headers to the list.
    HTTP_HEADERS.add( new NameValuePair( "Custom-Header", "custom/value" ) );

    // The mocked web connection.
    MockWebConnection connection = new MockWebConnection();
    connection.setDefaultResponse( RESPONSE_BODY, STATUS_CODE, STATUS_MESSAGE, CONTENT_TYPE, HTTP_HEADERS );

    // Creating the mock action using a WebClient with a mocked web
    // connection.
    mockAction = new XltRESTAction( new RESTCall() );
    mockAction.getWebClient().setWebConnection( connection );
}
 
开发者ID:Xceptance,项目名称:XRT-Xceptance-REST-Test,代码行数:22,代码来源:TestRESTCallResponse.java

示例6: setUp

import com.gargoylesoftware.htmlunit.util.NameValuePair; //导入依赖的package包/类
/**
 * Test setup. Creates the mocked action that needs to be used in every test
 * as previous action.
 * 
 * @throws Throwable
 */
@Before
public void setUp() throws Throwable
{
    // Adding HTTP headers to the list.
    HTTP_HEADERS.add( new NameValuePair( "Custom-Header", "custom/value" ) );

    // The mocked web connection.
    MockWebConnection connection = new MockWebConnection();
    connection.setDefaultResponse( RESPONSE_BODY, STATUS_CODE, STATUS_MESSAGE, CONTENT_TYPE, HTTP_HEADERS );

    // Creating the mock action using a WebClient with a mocked web
    // connection.
    mockAction = new XltRESTAction( new RESTCall() );
    mockAction.getWebClient().setWebConnection( connection );

    // Define result dir to prevent timers.csv exceptions.
    XltProperties.getInstance().setProperty( "com.xceptance.xlt.result-dir", "tmp" );
}
 
开发者ID:Xceptance,项目名称:XRT-Xceptance-REST-Test,代码行数:25,代码来源:TestDefaultValidation.java

示例7: setUp

import com.gargoylesoftware.htmlunit.util.NameValuePair; //导入依赖的package包/类
/**
 * Test setup. Creates the mocked action that needs to be used in every test as previous action.
 *
 * @throws Throwable
 */
@Before
public void setUp() throws Throwable
{
    // Adding HTTP headers to the list.
    HTTP_HEADERS.add( new NameValuePair( "Custom-Header", "custom/value" ) );

    // The mocked web connection.
    MockWebConnection connection = new MockWebConnection();
    connection.setDefaultResponse( RESPONSE_BODY, STATUS_CODE, STATUS_MESSAGE, CONTENT_TYPE, HTTP_HEADERS );

    // Creating the mock action using a WebClient with a mocked web
    // connection.
    mockAction = new XltRESTAction( new RESTCall() );
    mockAction.getWebClient().setWebConnection( connection );
}
 
开发者ID:Xceptance,项目名称:XRT-Xceptance-REST-Test,代码行数:21,代码来源:TestPreprocessing.java

示例8: getHtmlPageHtmlUnit

import com.gargoylesoftware.htmlunit.util.NameValuePair; //导入依赖的package包/类
/**
 * HtmlUnit을 이용한 HTML 코드 파싱.
 * @param eachArchiveAddress 실제 만화가 담긴 아카이브 주소
 * @return 성공 시 html 코드를 리턴
 */
private String getHtmlPageHtmlUnit(String eachArchiveAddress) throws Exception {
	/* 필수! 로그 메세지 출력 안함 -> HtmlUnit 이용시 Verbose한 로그들이 너무 많아서 다 끔 */
	java.util.logging.Logger.getLogger("com.gargoylesoftware").setLevel(Level.OFF); 
	System.setProperty("org.apache.commons.logging.Log", "org.apache.commons.logging.impl.NoOpLog");
	
	System.out.print("일반 연결 시도중 ... ");
	
	WebClient webClient = new WebClient();
	webClient.getOptions().setRedirectEnabled(true);
	
	WebRequest req = new WebRequest(new URL(eachArchiveAddress));
	req.setHttpMethod(HttpMethod.POST);
	req.setAdditionalHeader("User-Agent", UserAgent.getUserAgent());
	req.setAdditionalHeader("Accept-Encoding", "gzip"); //20171126 gzip 추가
	req.getRequestParameters().add(new NameValuePair("pass", PASSWORD)); //비밀번호 post 방식 전송
	
	HtmlPage page = webClient.getPage(req);
	
	//Html코드를 포함한 페이지 소스코드가 담길 스트링
	String pageSource = page.asXml();
	
	/** 여기도 페이지 파싱 실패 시 검증하는 코드 들어가야 됨 **/
	
	webClient.close();
	System.out.println("성공");
	return pageSource;
}
 
开发者ID:occidere,项目名称:MMDownloader,代码行数:33,代码来源:Downloader.java

示例9: webResponseData

import com.gargoylesoftware.htmlunit.util.NameValuePair; //导入依赖的package包/类
private WebResponseData webResponseData() throws IOException {
	List<NameValuePair> responseHeaders = responseHeaders();
	int statusCode = (this.response.getRedirectedUrl() != null ?
			HttpStatus.MOVED_PERMANENTLY.value() : this.response.getStatus());
	String statusMessage = statusMessage(statusCode);
	return new WebResponseData(this.response.getContentAsByteArray(), statusCode, statusMessage, responseHeaders);
}
 
开发者ID:langtianya,项目名称:spring4-understanding,代码行数:8,代码来源:MockWebResponseBuilder.java

示例10: buildRequestParameterMapViaWebRequestDotSetRequestParametersWithSingleRequestParam

import com.gargoylesoftware.htmlunit.util.NameValuePair; //导入依赖的package包/类
@Test
public void buildRequestParameterMapViaWebRequestDotSetRequestParametersWithSingleRequestParam() {
	webRequest.setRequestParameters(asList(new NameValuePair("name", "value")));

	MockHttpServletRequest actualRequest = requestBuilder.buildRequest(servletContext);

	assertThat(actualRequest.getParameterMap().size(), equalTo(1));
	assertThat(actualRequest.getParameter("name"), equalTo("value"));
}
 
开发者ID:langtianya,项目名称:spring4-understanding,代码行数:10,代码来源:HtmlUnitRequestBuilderTests.java

示例11: buildRequestParameterMapViaWebRequestDotSetRequestParametersWithSingleRequestParamWithNullValue

import com.gargoylesoftware.htmlunit.util.NameValuePair; //导入依赖的package包/类
@Test
public void buildRequestParameterMapViaWebRequestDotSetRequestParametersWithSingleRequestParamWithNullValue() {
	webRequest.setRequestParameters(asList(new NameValuePair("name", null)));

	MockHttpServletRequest actualRequest = requestBuilder.buildRequest(servletContext);

	assertThat(actualRequest.getParameterMap().size(), equalTo(1));
	assertThat(actualRequest.getParameter("name"), nullValue());
}
 
开发者ID:langtianya,项目名称:spring4-understanding,代码行数:10,代码来源:HtmlUnitRequestBuilderTests.java

示例12: buildRequestParameterMapViaWebRequestDotSetRequestParametersWithSingleRequestParamWithEmptyValue

import com.gargoylesoftware.htmlunit.util.NameValuePair; //导入依赖的package包/类
@Test
public void buildRequestParameterMapViaWebRequestDotSetRequestParametersWithSingleRequestParamWithEmptyValue() {
	webRequest.setRequestParameters(asList(new NameValuePair("name", "")));

	MockHttpServletRequest actualRequest = requestBuilder.buildRequest(servletContext);

	assertThat(actualRequest.getParameterMap().size(), equalTo(1));
	assertThat(actualRequest.getParameter("name"), equalTo(""));
}
 
开发者ID:langtianya,项目名称:spring4-understanding,代码行数:10,代码来源:HtmlUnitRequestBuilderTests.java

示例13: buildRequestParameterMapViaWebRequestDotSetRequestParametersWithSingleRequestParamWithValueSetToSpace

import com.gargoylesoftware.htmlunit.util.NameValuePair; //导入依赖的package包/类
@Test
public void buildRequestParameterMapViaWebRequestDotSetRequestParametersWithSingleRequestParamWithValueSetToSpace() {
	webRequest.setRequestParameters(asList(new NameValuePair("name", " ")));

	MockHttpServletRequest actualRequest = requestBuilder.buildRequest(servletContext);

	assertThat(actualRequest.getParameterMap().size(), equalTo(1));
	assertThat(actualRequest.getParameter("name"), equalTo(" "));
}
 
开发者ID:langtianya,项目名称:spring4-understanding,代码行数:10,代码来源:HtmlUnitRequestBuilderTests.java

示例14: buildRequestParameterMapViaWebRequestDotSetRequestParametersWithMultipleRequestParams

import com.gargoylesoftware.htmlunit.util.NameValuePair; //导入依赖的package包/类
@Test
public void buildRequestParameterMapViaWebRequestDotSetRequestParametersWithMultipleRequestParams() {
	webRequest.setRequestParameters(asList(new NameValuePair("name1", "value1"), new NameValuePair("name2", "value2")));

	MockHttpServletRequest actualRequest = requestBuilder.buildRequest(servletContext);

	assertThat(actualRequest.getParameterMap().size(), equalTo(2));
	assertThat(actualRequest.getParameter("name1"), equalTo("value1"));
	assertThat(actualRequest.getParameter("name2"), equalTo("value2"));
}
 
开发者ID:langtianya,项目名称:spring4-understanding,代码行数:11,代码来源:HtmlUnitRequestBuilderTests.java

示例15: setUp

import com.gargoylesoftware.htmlunit.util.NameValuePair; //导入依赖的package包/类
@Before
public void setUp() throws Exception {
	request = new WebRequest(new URL("http://localhost/"));
	WebResponseData data = new WebResponseData("".getBytes("UTF-8"), 200, "", Collections.<NameValuePair> emptyList());
	expectedResponse = new WebResponse(data, request, 100L);
	webConnection = new DelegatingWebConnection(defaultConnection,
		new DelegateWebConnection(matcher1, connection1), new DelegateWebConnection(matcher2, connection2));
}
 
开发者ID:langtianya,项目名称:spring4-understanding,代码行数:9,代码来源:DelegatingWebConnectionTests.java


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