本文整理了Java中jodd.http.HttpRequest.method()
方法的一些代码示例,展示了HttpRequest.method()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。HttpRequest.method()
方法的具体详情如下:
包路径:jodd.http.HttpRequest
类名称:HttpRequest
方法名:method
[英]Returns request method.
[中]返回请求方法。
代码示例来源:origin: oblac/jodd
/**
* Generic request builder, usually used when method is a variable.
* Otherwise, use one of the other static request builder methods.
*/
public static HttpRequest create(final String method, final String destination) {
return new HttpRequest()
.method(method.toUpperCase())
.set(destination);
}
代码示例来源:origin: oblac/jodd
/**
* Builds a DELETE request.
*/
public static HttpRequest delete(final String destination) {
return new HttpRequest()
.method(HttpMethod.DELETE)
.set(destination);
}
/**
代码示例来源:origin: oblac/jodd
/**
* Builds an OPTIONS request.
*/
public static HttpRequest options(final String destination) {
return new HttpRequest()
.method(HttpMethod.OPTIONS)
.set(destination);
}
代码示例来源:origin: oblac/jodd
/**
* Builds a GET request.
*/
public static HttpRequest get(final String destination) {
return new HttpRequest()
.method(HttpMethod.GET)
.set(destination);
}
/**
代码示例来源:origin: oblac/jodd
/**
* Builds a CONNECT request.
*/
public static HttpRequest connect(final String destination) {
return new HttpRequest()
.method(HttpMethod.CONNECT)
.set(destination);
}
/**
代码示例来源:origin: oblac/jodd
/**
* Builds a PUT request.
*/
public static HttpRequest put(final String destination) {
return new HttpRequest()
.method(HttpMethod.PUT)
.set(destination);
}
/**
代码示例来源:origin: oblac/jodd
/**
* Builds a PATCH request.
*/
public static HttpRequest patch(final String destination) {
return new HttpRequest()
.method(HttpMethod.PATCH)
.set(destination);
}
/**
代码示例来源:origin: oblac/jodd
/**
* Builds a HEAD request.
*/
public static HttpRequest head(final String destination) {
return new HttpRequest()
.method(HttpMethod.HEAD)
.set(destination);
}
/**
代码示例来源:origin: oblac/jodd
/**
* Builds a POST request.
*/
public static HttpRequest post(final String destination) {
return new HttpRequest()
.method(HttpMethod.POST)
.set(destination);
}
/**
代码示例来源:origin: oblac/jodd
/**
* Builds a TRACE request.
*/
public static HttpRequest trace(final String destination) {
return new HttpRequest()
.method(HttpMethod.TRACE)
.set(destination);
}
/**
代码示例来源:origin: oblac/jodd
public static HttpRequest readFrom(final InputStream in, final String encoding) {
BufferedReader reader;
try {
reader = new BufferedReader(new InputStreamReader(in, encoding));
} catch (UnsupportedEncodingException uneex) {
return null;
}
final HttpRequest httpRequest = new HttpRequest();
httpRequest.headers.clear();
final String line;
try {
line = reader.readLine();
} catch (IOException ioex) {
throw new HttpException(ioex);
}
if (!StringUtil.isBlank(line)) {
String[] s = StringUtil.splitc(line, ' ');
httpRequest.method(s[0]);
httpRequest.path(s[1]);
httpRequest.httpVersion(s[2]);
httpRequest.readHeaders(reader);
httpRequest.readBody(reader);
}
return httpRequest;
}
代码示例来源:origin: oblac/jodd
String originalMethod = httpRequest.method();
httpRequest = new HttpRequest()
.method(originalMethod)
.set(newPath);
continue;
代码示例来源:origin: oblac/jodd
@Test
void test394() {
HttpRequest request = HttpRequest.get("https://jodd.org/random link");
assertEquals("GET", request.method());
assertEquals("https://jodd.org/random link", request.url());
request = HttpRequest.get("https://jodd.org/random link?q=1");
assertEquals("1", request.query().get("q"));
String badUrl = "httpsjodd.org/random link?q=1:// GET";
try {
HttpRequest.get(badUrl).send();
fail("error");
}
catch (HttpException he) {
assertTrue(he.getMessage().contains(badUrl));
}
}
代码示例来源:origin: oblac/jodd
@Test
void testFileUpload() throws IOException {
HttpRequest request = HttpRequest.get("http://jodd.org/?id=173");
request.header("User-Agent", "Scaly").form("one", "funny");
File tempFile = FileUtil.createTempFile();
tempFile.deleteOnExit();
FileUtil.writeString(tempFile, "qwerty");
request.form("two", tempFile);
byte[] bytes = request.toByteArray();
// read
HttpRequest request2 = HttpRequest.readFrom(new ByteArrayInputStream(bytes));
HttpMultiMap<?> httpParams2 = request2.form();
assertEquals(request.method(), request2.method());
assertEquals(request.path(), request2.path());
assertEquals(request.queryString(), request2.queryString());
assertEquals(request.header("User-Agent"), request2.header("User-Agent"));
assertEquals(request.header("Content-Type"), request2.header("content-type"));
assertEquals(request.header("Content-Length"), request2.header("content-length"));
HttpMultiMap<?> params1 = request.form();
HttpMultiMap<?> params2 = request2.form();
assertEquals(params1.size(), params2.size());
assertEquals(params2.get("one"), params2.get("one"));
FileUpload fu = (FileUpload) httpParams2.get("two");
assertEquals(6, fu.getSize());
String str = new String(fu.getFileContent());
assertEquals("qwerty", str);
tempFile.delete();
}
代码示例来源:origin: oblac/jodd
@Test
void testInOutForm() {
HttpRequest request = HttpRequest.get("http://jodd.org/?id=173");
request.header("User-Agent", "Scaly");
request.form("one", "funny");
byte[] bytes = request.toByteArray();
// read
HttpRequest request2 = HttpRequest.readFrom(new ByteArrayInputStream(bytes));
assertEquals(request.method(), request2.method());
assertEquals(request.path(), request2.path());
assertEquals(request.queryString(), request2.queryString());
assertEquals(request.header("User-Agent"), request2.header("User-Agent"));
assertEquals(request.header("Content-Type"), request2.header("content-type"));
assertEquals(request.header("Content-Length"), request2.header("content-length"));
HttpMultiMap<?> params1 = request.form();
HttpMultiMap<?> params2 = request2.form();
assertEquals(params1.size(), params2.size());
assertEquals(params2.get("one"), params2.get("one"));
}
代码示例来源:origin: oblac/jodd
httpRequest.set("GET http://jodd.org:173/index.html?light=true");
assertEquals("GET", httpRequest.method());
assertEquals("http", httpRequest.protocol());
assertEquals("jodd.org", httpRequest.host());
httpRequest.set("http://jodd.org:173/index.html?light=true");
assertEquals("GET", httpRequest.method());
assertEquals("http", httpRequest.protocol());
assertEquals("jodd.org", httpRequest.host());
assertEquals("GET", httpRequest.method());
assertEquals("http", httpRequest.protocol());
assertEquals("jodd.org", httpRequest.host());
assertEquals("GET", httpRequest.method());
assertEquals("http", httpRequest.protocol());
assertEquals("jodd.org", httpRequest.host());
assertEquals("GET", httpRequest.method());
assertEquals("http", httpRequest.protocol());
assertEquals("localhost", httpRequest.host());
assertEquals("GET", httpRequest.method());
assertEquals("http", httpRequest.protocol());
assertEquals("jodd.org", httpRequest.host());
代码示例来源:origin: org.jodd/jodd-http
/**
* Generic request builder, usually used when method is a variable.
* Otherwise, use one of the other static request builder methods.
*/
public static HttpRequest create(final String method, final String destination) {
return new HttpRequest()
.method(method.toUpperCase())
.set(destination);
}
代码示例来源:origin: org.jodd/jodd-http
/**
* Builds a POST request.
*/
public static HttpRequest post(final String destination) {
return new HttpRequest()
.method(HttpMethod.POST)
.set(destination);
}
/**
代码示例来源:origin: org.jodd/jodd-http
/**
* Builds a HEAD request.
*/
public static HttpRequest head(final String destination) {
return new HttpRequest()
.method(HttpMethod.HEAD)
.set(destination);
}
/**
代码示例来源:origin: org.jodd/jodd-http
/**
* Builds a GET request.
*/
public static HttpRequest get(final String destination) {
return new HttpRequest()
.method(HttpMethod.GET)
.set(destination);
}
/**
内容来源于网络,如有侵权,请联系作者删除!