Patch Request Android Volley

痞子三分冷 提交于 2019-12-18 13:14:10

问题


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?


回答1:


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.



来源:https://stackoverflow.com/questions/19797842/patch-request-android-volley

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!