mirror of
https://gitee.com/durcframework/SOP.git
synced 2025-08-11 21:57:56 +08:00
1.13.5
This commit is contained in:
@@ -118,7 +118,7 @@ public class OpenHttp {
|
||||
* @return
|
||||
* @throws IOException
|
||||
*/
|
||||
public String request(String url, Map<String, String> form, Map<String, String> header, String method) throws IOException {
|
||||
public String request(String url, Map<String, String> form, Map<String, String> header, HTTPMethod method) throws IOException {
|
||||
Request.Builder requestBuilder = buildRequestBuilder(url, form, method);
|
||||
// 添加header
|
||||
addHeader(requestBuilder, header);
|
||||
@@ -134,21 +134,21 @@ public class OpenHttp {
|
||||
}
|
||||
}
|
||||
|
||||
public static Request.Builder buildRequestBuilder(String url, Map<String, String> form, String method) {
|
||||
public static Request.Builder buildRequestBuilder(String url, Map<String, String> form, HTTPMethod method) {
|
||||
switch (method) {
|
||||
case "get":
|
||||
case GET:
|
||||
return new Request.Builder()
|
||||
.url(buildHttpUrl(url, form))
|
||||
.get();
|
||||
case "head":
|
||||
case HEAD:
|
||||
return new Request.Builder()
|
||||
.url(buildHttpUrl(url, form))
|
||||
.head();
|
||||
case "put":
|
||||
case PUT:
|
||||
return new Request.Builder()
|
||||
.url(url)
|
||||
.put(buildFormBody(form));
|
||||
case "delete":
|
||||
case DELETE:
|
||||
return new Request.Builder()
|
||||
.url(url)
|
||||
.delete(buildFormBody(form));
|
||||
@@ -241,5 +241,22 @@ public class OpenHttp {
|
||||
this.httpClient = httpClient;
|
||||
}
|
||||
|
||||
public enum HTTPMethod {
|
||||
GET,
|
||||
POST,
|
||||
PUT,
|
||||
HEAD,
|
||||
DELETE;
|
||||
|
||||
private HTTPMethod() {
|
||||
}
|
||||
|
||||
public String value() {
|
||||
return this.name();
|
||||
}
|
||||
|
||||
public static HTTPMethod fromValue(String v) {
|
||||
return valueOf(v.toUpperCase());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user