Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Patch Request Android Volley

I'm currently using Android's Volley networking library in a project I'm working on. I've pulled down the master branch of volley from https://android.googlesource.com/platform/frameworks/volley/, so my library project should be up to date, but only supports the following request methods:

/**
 * Supported request methods.
 */
public interface Method {
    int DEPRECATED_GET_OR_POST = -1;
    int GET = 0;
    int POST = 1;
    int PUT = 2;
    int DELETE = 3;
}

It probably wouldn't be much trouble to extend the library to support patch requests, so my question is why wouldn't patch requests be supported by the base library? Also, could anyone suggest any good git branches that have already added this support?

like image 418
Submersed Avatar asked Nov 05 '13 20:11

Submersed


1 Answers

I finally found an answer to this question. It is very stupid. The problem is not with the Volley framework. HTTPUrlConnection of Java does not support PATCH. There are way on the internet that uses Java Reflection to set the method object to PATCH but they brings additional problems.

I finally solved this problem using X-HTTP-Method-Override header. I made a normal POST request with body even and add this header like below.

X-HTTP-Method-Override: PATCH

and it worked. Your web server side should support method overriding though.

like image 172
tasomaniac Avatar answered Sep 27 '22 22:09

tasomaniac