mirror of
https://github.com/silkimen/cordova-plugin-advanced-http.git
synced 2024-10-06 09:12:13 +08:00
patch method android
This commit is contained in:
parent
52ccfc6aca
commit
09da3c9a97
@ -236,6 +236,11 @@ public class HttpRequest {
|
||||
*/
|
||||
public static final String METHOD_POST = "POST";
|
||||
|
||||
/**
|
||||
* 'PATCH' request method
|
||||
*/
|
||||
public static final String METHOD_PATCH = "PATCH";
|
||||
|
||||
/**
|
||||
* 'PUT' request method
|
||||
*/
|
||||
@ -1176,6 +1181,70 @@ public class HttpRequest {
|
||||
return post(encode ? encode(url) : url);
|
||||
}
|
||||
|
||||
/**
|
||||
* Start a 'PATCH' request to the given URL
|
||||
*
|
||||
* @param url
|
||||
* @return request
|
||||
* @throws HttpRequestException
|
||||
*/
|
||||
public static HttpRequest patch(final CharSequence url)
|
||||
throws HttpRequestException {
|
||||
return new HttpRequest(url, METHOD_PATCH);
|
||||
}
|
||||
|
||||
/**
|
||||
* Start a 'PATCH' request to the given URL
|
||||
*
|
||||
* @param url
|
||||
* @return request
|
||||
* @throws HttpRequestException
|
||||
*/
|
||||
public static HttpRequest patch(final URL url) throws HttpRequestException {
|
||||
return new HttpRequest(url, METHOD_PATCH);
|
||||
}
|
||||
|
||||
/**
|
||||
* Start a 'PATCH' request to the given URL along with the query params
|
||||
*
|
||||
* @param baseUrl
|
||||
* @param params
|
||||
* the query parameters to include as part of the baseUrl
|
||||
* @param encode
|
||||
* true to encode the full URL
|
||||
*
|
||||
* @see #append(CharSequence, Map)
|
||||
* @see #encode(CharSequence)
|
||||
*
|
||||
* @return request
|
||||
*/
|
||||
public static HttpRequest patch(final CharSequence baseUrl,
|
||||
final Map<?, ?> params, final boolean encode) {
|
||||
String url = append(baseUrl, params);
|
||||
return patch(encode ? encode(url) : url);
|
||||
}
|
||||
|
||||
/**
|
||||
* Start a 'PATCH' request to the given URL along with the query params
|
||||
*
|
||||
* @param baseUrl
|
||||
* @param encode
|
||||
* true to encode the full URL
|
||||
* @param params
|
||||
* the name/value query parameter pairs to include as part of the
|
||||
* baseUrl
|
||||
*
|
||||
* @see #append(CharSequence, Object...)
|
||||
* @see #encode(CharSequence)
|
||||
*
|
||||
* @return request
|
||||
*/
|
||||
public static HttpRequest patch(final CharSequence baseUrl,
|
||||
final boolean encode, final Object... params) {
|
||||
String url = append(baseUrl, params);
|
||||
return patch(encode ? encode(url) : url);
|
||||
}
|
||||
|
||||
/**
|
||||
* Start a 'PUT' request to the given URL
|
||||
*
|
||||
|
@ -16,8 +16,8 @@ import com.github.kevinsawicki.http.HttpRequest;
|
||||
import com.github.kevinsawicki.http.HttpRequest.HttpRequestException;
|
||||
|
||||
class CordovaHttpPatch extends CordovaHttp implements Runnable {
|
||||
public CordovaHttpPatch(String urlString, JSONObject data, String serializerName, JSONObject headers, CallbackContext callbackContext, int timeout) {
|
||||
super(urlString, data, serializerName, headers, timeout, callbackContext);
|
||||
public CordovaHttpPatch(String urlString, JSONObject params, String serializerName, JSONObject headers, CallbackContext callbackContext, int timeout) {
|
||||
super(urlString, params, serializerName, headers, timeout, callbackContext);
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -26,6 +26,7 @@ class CordovaHttpPatch extends CordovaHttp implements Runnable {
|
||||
HttpRequest request = HttpRequest.patch(this.getUrlString());
|
||||
|
||||
request.readTimeout(this.getRequestTimeout());
|
||||
this.setupRedirect(request);
|
||||
this.setupSecurity(request);
|
||||
request.acceptCharset(CHARSET);
|
||||
request.headers(this.getHeadersMap());
|
||||
@ -43,13 +44,13 @@ class CordovaHttpPatch extends CordovaHttp implements Runnable {
|
||||
JSONObject response = new JSONObject();
|
||||
|
||||
this.addResponseHeaders(request, response);
|
||||
response.patch("status", code);
|
||||
response.put("status", code);
|
||||
|
||||
if (code >= 200 && code < 300) {
|
||||
response.patch("data", body);
|
||||
response.put("data", body);
|
||||
this.getCallbackContext().success(response);
|
||||
} else {
|
||||
response.patch("error", body);
|
||||
response.put("error", body);
|
||||
this.getCallbackContext().error(response);
|
||||
}
|
||||
} catch (JSONException e) {
|
||||
|
@ -60,7 +60,16 @@ public class CordovaHttpPlugin extends CordovaPlugin {
|
||||
CordovaHttpPut put = new CordovaHttpPut(urlString, params, serializerName, headers, callbackContext, timeoutInMilliseconds);
|
||||
|
||||
cordova.getThreadPool().execute(put);
|
||||
} else if (action.equals("delete")) {
|
||||
} else if (action.equals("patch")) {
|
||||
String urlString = args.getString(0);
|
||||
JSONObject params = args.getJSONObject(1);
|
||||
String serializerName = args.getString(2);
|
||||
JSONObject headers = args.getJSONObject(3);
|
||||
CordovaHttpPatch patch = new CordovaHttpPatch(urlString, params, serializerName, headers, callbackContext);
|
||||
|
||||
cordova.getThreadPool().execute(patch);
|
||||
}
|
||||
else if (action.equals("delete")) {
|
||||
String urlString = args.getString(0);
|
||||
JSONObject params = args.getJSONObject(1);
|
||||
JSONObject headers = args.getJSONObject(2);
|
||||
|
Loading…
Reference in New Issue
Block a user