本文整理了Java中jodd.http.HttpResponse.statusCode()
方法的一些代码示例,展示了HttpResponse.statusCode()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。HttpResponse.statusCode()
方法的具体详情如下:
包路径:jodd.http.HttpResponse
类名称:HttpResponse
方法名:statusCode
[英]Returns response status code.
[中]返回响应状态代码。
代码示例来源:origin: oblac/jodd
httpResponse.statusCode(Integer.parseInt(line.substring(ndx, ndx2).trim()));
httpResponse.statusCode(-1);
代码示例来源:origin: oblac/jodd
/**
* {@link #open() Opens connection} if not already open, sends request,
* reads response and closes the request. If keep-alive mode is enabled
* connection will not be closed.
*/
public HttpResponse send() {
if (!followRedirects) {
return _send();
}
int redirects = this.maxRedirects;
while (redirects > 0) {
redirects--;
final HttpResponse httpResponse = _send();
final int statusCode = httpResponse.statusCode();
if (HttpStatus.isRedirect(statusCode)) {
_reset();
set(httpResponse.location());
continue;
}
return httpResponse;
}
throw new HttpException("Max number of redirects exceeded: " + this.maxRedirects);
}
代码示例来源:origin: oblac/jodd
@Test
void testRawResponse6() throws IOException {
URL data = RawTest.class.getResource("6-response.txt");
String fileContent = FileUtil.readString(data.getFile());
fileContent = StringUtil.replace(fileContent, "\n", "\r\n");
fileContent = StringUtil.replace(fileContent, "\r\r\n", "\r\n");
HttpResponse response = HttpResponse.readFrom(new ByteArrayInputStream(fileContent.getBytes("UTF-8")));
assertEquals(200, response.statusCode());
assertEquals("", response.statusPhrase);
String body = response.bodyText();
assertEquals(
"Wikipedia in\n" +
"\n" +
"chunks.", body.replace("\r\n", "\n"));
assertEquals("TheData", response.header("SomeAfterHeader"));
}
代码示例来源:origin: oblac/jodd
@Test
void testUploadWithUploadable() throws IOException {
HttpResponse response = HttpRequest
.post("http://localhost:8173/echo2")
.multipart(true)
.form("id", "12")
.form("file", new ByteArrayUploadable(
"upload тест".getBytes(StringPool.UTF_8), "d ст", MimeTypes.MIME_TEXT_PLAIN))
.send();
assertEquals(200, response.statusCode());
assertEquals("OK", response.statusPhrase());
assertEquals("12", Data.ref.params.get("id"));
assertEquals("upload тест", Data.ref.parts.get("file"));
assertEquals("d ст", Data.ref.fileNames.get("file"));
}
代码示例来源:origin: oblac/jodd
httpResponse = new HttpResponse();
httpResponse.assignHttpRequest(httpRequest);
httpResponse.statusCode(503);
httpResponse.statusPhrase("Service unavailable. " + ExceptionUtil.message(httpException));
int statusCode = httpResponse.statusCode();
代码示例来源:origin: oblac/jodd
@Test
void testDirect() {
HttpResponse response = HttpRequest.get("http://localhost:1080/get_books").send();
assertEquals(200, response.statusCode());
assertTrue(response.body().contains("Tatum"));
proxy.verify(request().withPath("/get_books"), exactly(0));
}
代码示例来源:origin: oblac/jodd
@Test
@Disabled
void testHttpProxy() {
SocketHttpConnectionProvider s = new SocketHttpConnectionProvider();
s.useProxy(ProxyInfo.httpProxy("localhost", 1090, null, null));
HttpResponse response = HttpRequest.get("http://localhost:1080/get_books")
.withConnectionProvider(s)
.send();
assertEquals(200, response.statusCode());
assertTrue(response.body().contains("Tatum"));
}
代码示例来源:origin: oblac/jodd
@Test
void testDirectHttps() {
HttpResponse response = HttpRequest.get("https://localhost:1080/get_books").trustAllCerts(true).send();
assertEquals(200, response.statusCode());
assertTrue(response.body().contains("Tatum"));
proxy.verify(request().withPath("/get_books"), exactly(0));
}
代码示例来源:origin: oblac/jodd
@Test
void testEcho() throws IOException {
EchoTestServer echoTestServer = new EchoTestServer();
HttpResponse response = HttpRequest.get("http://localhost:8081/hello?id=12").send();
assertEquals(200, response.statusCode());
assertEquals("OK", response.statusPhrase());
assertEquals("GET", echoTestServer.method);
assertEquals("/hello", echoTestServer.uri);
assertEquals(1, echoTestServer.params.size());
assertEquals("12", echoTestServer.params.get("id"));
assertEquals("GET /hello", response.body());
echoTestServer.stop();
}
代码示例来源:origin: oblac/jodd
@Test
void testUploadWithUploadable() throws IOException {
EchoTestServer echoTestServer = new EchoTestServer();
HttpResponse response = HttpRequest
.post("http://localhost:8081/hello")
.multipart(true)
.form("id", "12")
.form("file", new ByteArrayUploadable(
"upload тест".getBytes(StringPool.UTF_8), "d ст", MimeTypes.MIME_TEXT_PLAIN))
.send();
assertEquals(200, response.statusCode());
assertEquals("OK", response.statusPhrase());
assertEquals("POST", echoTestServer.method);
assertEquals("12", echoTestServer.params.get("id"));
File uploadedFile = new File(echoTestServer.files.get("file").toString());
assertNotNull(uploadedFile);
assertEquals("upload тест", FileUtil.readString(uploadedFile));
assertEquals("POST /hello", response.body());
echoTestServer.stop();
}
代码示例来源:origin: oblac/jodd
@Test
void testBrowserRedirect() {
HttpBrowser httpBrowser = new HttpBrowser();
httpBrowser.sendRequest(HttpRequest.get("localhost:8173/redirect"));
HttpResponse httpResponse = httpBrowser.getHttpResponse();
assertEquals(200, httpResponse.statusCode());
assertEquals("target!", httpResponse.body());
}
代码示例来源:origin: oblac/jodd
@Test
void testUpload() throws IOException {
EchoTestServer echoTestServer = new EchoTestServer();
File file = FileUtil.createTempFile();
file.deleteOnExit();
FileUtil.writeString(file, "upload тест");
assertEquals("upload тест", FileUtil.readString(file));
HttpResponse response = HttpRequest
.post("http://localhost:8081/hello")
.form("id", "12")
.form("file", file)
.send();
assertEquals(200, response.statusCode());
assertEquals("OK", response.statusPhrase());
assertEquals("POST", echoTestServer.method);
assertEquals("12", echoTestServer.params.get("id"));
File uploadedFile = new File(echoTestServer.files.get("file").toString());
assertNotNull(uploadedFile);
assertEquals("upload тест", FileUtil.readString(uploadedFile));
assertEquals("POST /hello", response.body());
echoTestServer.stop();
file.delete();
}
代码示例来源:origin: oblac/jodd
@Test
void testUploadWithMonitor() throws IOException {
EchoTestServer echoTestServer = new EchoTestServer();
File file = FileUtil.createTempFile();
file.deleteOnExit();
FileUtil.writeString(file, StringUtil.repeat('A', 1024));
final StringBuilder sb = new StringBuilder();
HttpResponse response = HttpRequest
.post("http://localhost:8081/hello")
.form("id", "12")
.form("file", file)
.monitor(new HttpProgressListener() {
@Override
public void transferred(int len) {
sb.append(":" + len);
}
})
.send();
assertEquals(200, response.statusCode());
assertEquals("OK", response.statusPhrase());
echoTestServer.stop();
file.delete();
assertEquals(":0:512:1024:148", StringUtil.substring(sb.toString(), 0, -1));
}
代码示例来源:origin: oblac/jodd
assertEquals(200, response.statusCode());
代码示例来源:origin: oblac/jodd
@Test
void testSocks5Proxy() {
SocketHttpConnectionProvider s = new SocketHttpConnectionProvider();
s.useProxy(ProxyInfo.socks5Proxy("localhost", 1090, null, null));
HttpResponse response = HttpRequest.get("http://localhost:1080/get_books")
.withConnectionProvider(s)
.send();
assertEquals(200, response.statusCode());
assertTrue(response.body().contains("Tatum"));
proxy.verify(request().withPath("/get_books"), exactly(1));
}
代码示例来源:origin: oblac/jodd
@Test
void testSocks5ProxyWithHttps() {
SocketHttpConnectionProvider s = new SocketHttpConnectionProvider();
s.useProxy(ProxyInfo.socks5Proxy("localhost", 1090, null, null));
HttpResponse response = HttpRequest.get("https://localhost:1080/get_books")
.withConnectionProvider(s)
.trustAllCerts(true)
.send();
assertEquals(200, response.statusCode());
assertTrue(response.body().contains("Tatum"));
proxy.verify(request().withPath("/get_books"), exactly(1));
}
代码示例来源:origin: oblac/jodd
@Test
void testTimeout() {
HttpRequest httpRequest = HttpRequest.get("localhost:8173/slow");
httpRequest.timeout(1000);
try {
httpRequest.send();
fail("error");
}
catch(HttpException ignore) {
}
httpRequest = HttpRequest.get("localhost:8173/slow");
httpRequest.timeout(6000);
int status = httpRequest.send().statusCode();
assertEquals(200, status);
}
}
代码示例来源:origin: com.liferay.launchpad/api-client
clientResponse.status(response.statusCode(), response.statusPhrase());
clientResponse.body(response.bodyText());
代码示例来源:origin: org.jodd/jodd-http
/**
* {@link #open() Opens connection} if not already open, sends request,
* reads response and closes the request. If keep-alive mode is enabled
* connection will not be closed.
*/
public HttpResponse send() {
if (!followRedirects) {
return _send();
}
int redirects = this.maxRedirects;
while (redirects > 0) {
redirects--;
final HttpResponse httpResponse = _send();
final int statusCode = httpResponse.statusCode();
if (HttpStatus.isRedirect(statusCode)) {
_reset();
set(httpResponse.location());
continue;
}
return httpResponse;
}
throw new HttpException("Max number of redirects exceeded: " + this.maxRedirects);
}
代码示例来源:origin: com.liferay.launchpad/api-transport-jodd
clientResponse.statusCode(response.statusCode());
clientResponse.statusMessage(response.statusPhrase());
clientResponse.body(response.body());
内容来源于网络,如有侵权,请联系作者删除!