sreejith sreejith - 2 months ago 30
Java Question

Error in Volley Patch Unknown method 'PATCH'; must be one of [OPTIONS, GET, HEAD, POST, PUT, DELETE, TRACE]

StringRequest putRequest = new StringRequest(Request.Method.PATCH, url,
new Response.Listener<String>()
public void onResponse(String response)

Log.d("Response", response);

new Response.ErrorListener()
public void onErrorResponse(VolleyError error)

Log.d("Error.Response", error.toString());

) {

protected Map<String, String> getParams()
Map<String, String> params = new HashMap<String, String> ();
params.put("name", "My Name");
params.put("age", "11");

return params;



Are you sure you are using correct version of Volley Library? I just tried your code in Lollipop and it is working OK. If you are using Volley library as external project, check the Method interface of Request class in package. It should have a PATCH variable in it.

public interface Method {
        int DEPRECATED_GET_OR_POST = -1;
        int GET = 0;
        int POST = 1;
        int PUT = 2;
        int DELETE = 3;
        int HEAD = 4;
        int OPTIONS = 5;
        int TRACE = 6;
        int PATCH = 7;

If not, use the latest version of Volley library.


You are correct, it is showing this error in Kitkat, but not in Lollipop. I guess the main problem is that HTTPUrlConnection of Java does not support PATCH. (I guess it works in Lollipop because it is using Java 7 and HTTPUrlConnection of Java 7 supports PATCH method?) Anyhow, You can use the OkHttp Library to correct this problem. The okhttp-urlconnection module implements the

Add the following jar to your libs folder:

Create a OkHttpStack class:

package com.example.temp;    


import com.squareup.okhttp.OkHttpClient;
import com.squareup.okhttp.OkUrlFactory;

public class OkHttpStack extends HurlStack {
    private final OkUrlFactory mFactory;

    public OkHttpStack() {
        this(new OkHttpClient());

    public OkHttpStack(OkHttpClient client) {
        if (client == null) {
            throw new NullPointerException("Client must not be null.");
        mFactory = new OkUrlFactory(client);

    @Override protected HttpURLConnection createConnection(URL url) throws IOException {

Use the following constructor to create a Volley RequestQueue:

Volley.newRequestQueue(getApplicationContext(),new OkHttpStack()).add(putRequest);

It is working for me on Kitkat now.