本文整理了Java中jodd.http.HttpResponse.readFrom()
方法的一些代码示例,展示了HttpResponse.readFrom()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。HttpResponse.readFrom()
方法的具体详情如下:
包路径:jodd.http.HttpResponse
类名称:HttpResponse
方法名:readFrom
[英]Reads response input stream and returns HttpResponse. Supports both streamed and chunked response.
[中]
代码示例来源:origin: oblac/jodd
@Test
void testNoContentLength() throws IOException {
URL data = RawTest.class.getResource("3-response.txt");
byte[] fileContent = FileUtil.readBytes(data.getFile());
HttpResponse httpResponse = HttpResponse.readFrom(new ByteArrayInputStream(fileContent));
assertEquals("Body!", httpResponse.bodyText());
}
代码示例来源:origin: oblac/jodd
@Test
void testRawResponse4() throws IOException {
URL data = RawTest.class.getResource("4-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")));
String body = response.bodyText();
assertEquals(
"Wikipedia in\n" +
"\n" +
"chunks.", body.replace("\r\n", "\n"));
}
代码示例来源:origin: oblac/jodd
HttpResponse response = HttpResponse.readFrom(in);
代码示例来源:origin: oblac/jodd
@Test
void testRawResponse5() throws IOException {
URL data = RawTest.class.getResource("5-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")));
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 testNoBody() throws IOException {
/*HttpResponse httpResponse = HttpRequest.get("http://maps.googleapis.com/maps/api/geocode/json")
.query("address", "14621")
.query("sensor", "false")
.send();
*/
URL data = RawTest.class.getResource("2-response.txt");
byte[] fileContent = FileUtil.readBytes(data.getFile());
HttpResponse httpResponse = HttpResponse.readFrom(new ByteArrayInputStream(fileContent));
try {
httpResponse.bodyText();
} catch (Exception ex) {
fail(ex.toString());
}
assertEquals("", httpResponse.bodyText());
}
代码示例来源: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
private HttpResponse _send() {
if (httpConnection == null) {
open();
}
// sends data
final HttpResponse httpResponse;
try {
OutputStream outputStream = httpConnection.getOutputStream();
sendTo(outputStream);
InputStream inputStream = httpConnection.getInputStream();
httpResponse = HttpResponse.readFrom(inputStream);
httpResponse.assignHttpRequest(this);
} catch (IOException ioex) {
throw new HttpException(ioex);
}
boolean keepAlive = httpResponse.isConnectionPersistent();
if (!keepAlive) {
// closes connection if keep alive is false, or if counter reached 0
httpConnection.close();
httpConnection = null;
}
return httpResponse;
}
代码示例来源:origin: oblac/jodd
HttpResponse response = HttpResponse.readFrom(new ByteArrayInputStream(fileContent.getBytes("UTF-8")));
代码示例来源:origin: org.jodd/jodd-http
HttpResponse response = HttpResponse.readFrom(in);
代码示例来源:origin: org.jodd/jodd-http
private HttpResponse _send() {
if (httpConnection == null) {
open();
}
// sends data
final HttpResponse httpResponse;
try {
OutputStream outputStream = httpConnection.getOutputStream();
sendTo(outputStream);
InputStream inputStream = httpConnection.getInputStream();
httpResponse = HttpResponse.readFrom(inputStream);
httpResponse.assignHttpRequest(this);
} catch (IOException ioex) {
throw new HttpException(ioex);
}
boolean keepAlive = httpResponse.isConnectionPersistent();
if (!keepAlive) {
// closes connection if keep alive is false, or if counter reached 0
httpConnection.close();
httpConnection = null;
}
return httpResponse;
}
内容来源于网络,如有侵权,请联系作者删除!