@@ -10,6 +10,7 @@ import com.squareup.okhttp.FormEncodingBuilder;
10
10
import com.squareup.okhttp.MultipartBuilder;
11
11
import com.squareup.okhttp.MediaType;
12
12
import com.squareup.okhttp.Headers;
13
+ import com.squareup.okhttp.internal.http.HttpMethod;
13
14
14
15
import java.lang.reflect.Type;
15
16
@@ -698,7 +699,7 @@ public class ApiClient {
698
699
* Build HTTP call with the given options.
699
700
*
700
701
* @param path The sub-path of the HTTP URL
701
- * @param method The request method, one of "GET", "HEAD", "POST", "PUT", "PATCH" and "DELETE"
702
+ * @param method The request method, one of "GET", "HEAD", "OPTIONS", " POST", "PUT", "PATCH" and "DELETE"
702
703
* @param queryParams The query parameters
703
704
* @param body The request body object
704
705
* @param headerParams The header parameters
@@ -718,7 +719,7 @@ public class ApiClient {
718
719
if (contentType == null) contentType = " application/json" ;
719
720
720
721
RequestBody reqBody;
721
- if (" GET " .equals(method) || " HEAD " .equals (method)) {
722
+ if (! HttpMethod.permitsRequestBody (method)) {
722
723
reqBody = null;
723
724
} else if ("application/x-www-form-urlencoded".equals(contentType)) {
724
725
reqBody = buildRequestBodyFormEncoding(formParams);
@@ -736,28 +737,7 @@ public class ApiClient {
736
737
reqBody = RequestBody.create(MediaType.parse(contentType), serialize(body, contentType));
737
738
}
738
739
739
- Request request;
740
- if ("GET".equals(method)) {
741
- request = reqBuilder.get().build();
742
- } else if ("HEAD".equals(method)) {
743
- request = reqBuilder.head().build();
744
- } else if ("POST".equals(method)) {
745
- request = reqBuilder.post(reqBody).build();
746
- } else if ("PUT".equals(method)) {
747
- request = reqBuilder.put(reqBody).build();
748
- } else if ("PATCH".equals(method)) {
749
- request = reqBuilder.patch(reqBody).build();
750
- } else if ("DELETE".equals(method)) {
751
- if (reqBody == null) {
752
- // calling DELETE without sending a request body
753
- request = reqBuilder.delete().build();
754
- } else {
755
- request = reqBuilder.delete(reqBody).build();
756
- }
757
- } else {
758
- throw new ApiException(" unknown method type: " + method);
759
- }
760
-
740
+ Request request = reqBuilder.method(method, reqBody).build();
761
741
return httpClient.newCall(request);
762
742
}
763
743
0 commit comments