本文整理了Java中com.gargoylesoftware.htmlunit.WebResponse.getContentAsString()
方法的一些代码示例,展示了WebResponse.getContentAsString()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。WebResponse.getContentAsString()
方法的具体详情如下:
包路径:com.gargoylesoftware.htmlunit.WebResponse
类名称:WebResponse
方法名:getContentAsString
[英]Returns the response content as a string, using the charset/encoding specified in the server response.
[中]使用服务器响应中指定的字符集/编码,以字符串形式返回响应内容。
代码示例来源:origin: javaee-samples/javaee7-samples
/**
* Gets content from the path that's relative to the base URL on which the Arquillian test
* archive is deployed.
*
* @param path the path relative to the URL on which the Arquillian test is deployed
* @return the raw content as a string as returned by the server
*/
protected String getFromServerPath(final String path) {
respOnse= null;
for (int i=0; i<=3; i++) {
try {
respOnse= webClient.getPage(base + path).getWebResponse().getContentAsString();
if (!response.contains("The response wrapper must wrap the response obtained from getResponse()")) {
return response;
}
} catch (FailingHttpStatusCodeException | IOException e) {
throw new IllegalStateException(e);
}
}
return response;
}
代码示例来源:origin: spring-projects/spring-framework
private void assertMockMvcNotUsed(WebClient client, String url) throws Exception {
assertThat(getResponse(client, url).getContentAsString(), not(equalTo("mvc")));
}
代码示例来源:origin: spring-projects/spring-framework
private void assertMockMvcUsed(WebClient client, String url) throws Exception {
assertThat(getResponse(client, url).getContentAsString(), equalTo("mvc"));
}
代码示例来源:origin: spring-projects/spring-framework
@Test // SPR-14265
public void COOKIEsAreManaged() throws Exception {
this.mockMvc = MockMvcBuilders.standaloneSetup(new COOKIEController()).build();
WebClient client = MockMvcWebClientBuilder.mockMvcSetup(this.mockMvc).build();
assertThat(getResponse(client, "http://localhost/").getContentAsString(), equalTo("NA"));
assertThat(postResponse(client, "http://localhost/?COOKIE=foo").getContentAsString(), equalTo("Set"));
assertThat(getResponse(client, "http://localhost/").getContentAsString(), equalTo("foo"));
assertThat(deleteResponse(client, "http://localhost/").getContentAsString(), equalTo("Delete"));
assertThat(getResponse(client, "http://localhost/").getContentAsString(), equalTo("NA"));
}
代码示例来源:origin: spring-projects/spring-framework
@Test
public void buildContent() throws Exception {
this.response.getWriter().write("expected content");
WebResponse webRespOnse= this.responseBuilder.build();
assertThat(webResponse.getContentAsString(), equalTo("expected content"));
}
代码示例来源:origin: spring-projects/spring-framework
@Test
public void defaultContextPathEmpty() throws Exception {
WebConnection cOnn= this.builder.createConnection(this.client);
assertThat(getResponse(conn, "http://localhost/abc").getContentAsString(), equalTo(""));
}
代码示例来源:origin: spring-projects/spring-framework
@Test
public void defaultContextPathCustom() throws Exception {
WebConnection cOnn= this.builder.contextPath("/abc").createConnection(this.client);
assertThat(getResponse(conn, "http://localhost/abc/def").getContentAsString(), equalTo("/abc"));
}
代码示例来源:origin: spring-projects/spring-framework
@Test
public void forward() throws IOException {
this.webClient.setWebConnection(new MockMvcWebConnection(this.mockMvc, this.webClient, ""));
Page page = this.webClient.getPage("http://localhost/forward");
assertThat(page.getWebResponse().getContentAsString(), equalTo("hello"));
}
代码示例来源:origin: spring-projects/spring-framework
@Test // SPR-14066
public void COOKIEManagerShared() throws Exception {
this.mockMvc = MockMvcBuilders.standaloneSetup(new COOKIEController()).build();
WebClient client = MockMvcWebClientBuilder.mockMvcSetup(this.mockMvc).build();
assertThat(getResponse(client, "http://localhost/").getContentAsString(), equalTo("NA"));
client.getCOOKIEManager().addCOOKIE(new COOKIE("localhost", "COOKIE", "COOKIEManagerShared"));
assertThat(getResponse(client, "http://localhost/").getContentAsString(), equalTo("COOKIEManagerShared"));
}
代码示例来源:origin: spring-projects/spring-framework
@Test
public void verifyExampleInClassLevelJavadoc() throws Exception {
Assume.group(TestGroup.PERFORMANCE);
WebClient webClient = new WebClient();
MockMvc mockMvc = MockMvcBuilders.standaloneSetup().build();
MockMvcWebConnection mockCOnnection= new MockMvcWebConnection(mockMvc, webClient);
WebRequestMatcher cdnMatcher = new UrlRegexRequestMatcher(".*?//code.jquery.com/.*");
WebConnection httpCOnnection= new HttpWebConnection(webClient);
webClient.setWebConnection(
new DelegatingWebConnection(mockConnection, new DelegateWebConnection(cdnMatcher, httpConnection)));
Page page = webClient.getPage("http://code.jquery.com/jquery-1.11.0.min.js");
assertThat(page.getWebResponse().getStatusCode(), equalTo(200));
assertThat(page.getWebResponse().getContentAsString(), not(isEmptyString()));
}
代码示例来源:origin: stackoverflow.com
WebClient client = new WebClient();
Page page = client.getPage("http://stackoverflow.com/users/flair/97901.json");
WebResponse respOnse= page.getWebResponse();
if (response.getContentType().equals("application/json")) {
String json = response.getContentAsString();
Map
代码示例来源:origin: net.sourceforge.htmlunit/htmlunit
/**
* Returns the response content as a string, using the specified charset,
* rather than the charset/encoding specified in the server response.
* If there is a bom header the charset parameter will be overwritten by the bom.
* @param encoding the charset/encoding to use to convert the response content into a string
* @return the response content as a string or null if the content retrieval was failing
*/
public String getContentAsString(final Charset encoding) {
return getContentAsString(encoding, false);
}
代码示例来源:origin: net.sourceforge.htmlunit/htmlunit
/**
* {@inheritDoc}
* The default behavior of this method is to return getContentAsString(Charset) on the wrapped webResponse object.
*/
@Override
public String getContentAsString(final Charset encoding) {
return wrappedWebResponse_.getContentAsString(encoding);
}
代码示例来源:origin: net.sourceforge.htmlunit/htmlunit
/**
* {@inheritDoc}
* The default behavior of this method is to return getContentAsString(Charset, boolean)
* on the wrapped webResponse object.
*/
@Override
public String getContentAsString(final Charset encoding, final boolean ignoreUtf8Bom) {
return wrappedWebResponse_.getContentAsString(encoding, ignoreUtf8Bom);
}
代码示例来源:origin: net.sourceforge.htmlunit/htmlunit
/**
* {@inheritDoc}
* The default behavior of this method is to return getContentAsString() on the wrapped webResponse object.
*/
@Override
public String getContentAsString() {
return wrappedWebResponse_.getContentAsString(getContentCharset());
}
代码示例来源:origin: net.sourceforge.htmlunit/htmlunit
/**
* Returns the content of this page.
*
* @return the content of this page
*/
public String getContent() {
return getWebResponse().getContentAsString();
}
}
代码示例来源:origin: net.sourceforge.htmlunit/htmlunit
/**
* Returns the response content as a string, using the charset/encoding specified in the server response.
* @return the response content as a string, using the charset/encoding specified in the server response
* or null if the content retrieval was failing
*/
public String getContentAsString() {
return getContentAsString(getContentCharset());
}
代码示例来源:origin: weld/core
@Test
public void testOnCompleteCalledSuccesfully() throws Exception {
WebClient webClient = new WebClient();
webClient.getPage(getPath(AsyncServlet.TEST_COMPLETE));
Page results = webClient.getPage(contextPath + "Status");
assertTrue(results.getWebResponse().getContentAsString().contains("onComplete: true"));
}
代码示例来源:origin: weld/core
@Test
public void testCrossContextForward(@ArquillianResource @OperateOnDeployment(FIRST) URL firstContext) throws IOException {
Page page = new WebClient().getPage(firstContext + "forwarding");
assertEquals(200, page.getWebResponse().getStatusCode());
assertEquals("Hello World
", page.getWebResponse().getContentAsString());
}
}
代码示例来源:origin: jenkinsci/pipeline-model-definition-plugin
private JSONObject callStepsToJson(String jenkinsFileContent) throws IOException {
JenkinsRule.WebClient wc = j.createWebClient();
WebRequest req = new WebRequest(new URL(wc.getContextPath() + ModelConverterAction.PIPELINE_CONVERTER_URL + "/stepsToJson"), HttpMethod.POST);
assertNotNull(jenkinsFileContent);
NameValuePair pair = new NameValuePair("jenkinsfile", jenkinsFileContent);
req.setRequestParameters(Collections.singletonList(pair));
String rawResult = wc.getPage(req).getWebResponse().getContentAsString();
assertNotNull(rawResult);
return JSONObject.fromObject(rawResult);
}
}