补丁请求Android Volley [英] Patch Request Android Volley

查看:68
本文介绍了补丁请求Android Volley的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我目前正在一个正在使用的项目中使用Android的Volley网络库.我已经从 https://android.googlesource.com/platform/frameworks/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;
}

扩展该库以支持补丁程序请求不会很麻烦,所以我的问题是为什么基础库不支持补丁程序请求?另外,有人可以建议已经添加了此支持的任何好的git分支吗?

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?

推荐答案

我终于找到了这个问题的答案.这是非常愚蠢的.问题不在于Volley框架. Java的HTTPUrlConnection不支持PATCH.互联网上有一些使用Java Reflection将方法对象设置为PATCH的方法,但是它们带来了其他问题.

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.

我终于使用X-HTTP-Method-Override标头解决了这个问题.我用body发出了一个普通的POST请求,并像下面一样添加了此标头.

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

,它奏效了.您的Web服务器端应该支持方法覆盖.

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

这篇关于补丁请求Android Volley的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆