如何设置在排球请求自定义标题自定义、排球、如何设置、标题

2023-09-12 08:29:54 作者:心碎心痛心难控。

有谁知道如何可以自定义标题是凌空的要求设置。目前,有方法来设置正文内容的POST请求。我有一个简单的GET请求,但我需要通过自定义页眉非常久远。我不知道怎样JsonRequest类支持它。是否有可能呢? 让我知道如果你需要更多的细节......

Does anyone know how can custom headers be set for a Volley request. At the moment, there is way to set body content for a POST request. I've a simple GET request, but I need to pass the custom headers alongwith. I don't see how JsonRequest class supports it. Is it possible at all? Let me know if you need more details...

推荐答案

编辑:的我知道这不是回答被问这个问题,有没有删除一个公认的答案实际的方式,这回答关于如何添加URL参数相关的问题

I am aware that this is not answering the question that was asked, there is no actual way to delete an accepted answer and this answers related questions on how to add URL parameters

为了增加你需要使用像这样的自定义页眉:

in order to add custom headers you need to use something like this:

Request request = new Request(
   Method.GET,
   url,
   Listener listener,
   ErrorListener errorListener) {
    @Override
    public HashMap<String, String> getParams() {
        HashMap<String, String> params = new HashMap<String, String>();
        params.put("custom_header1", "123");
        params.put("custom_header2", "456");

        return params;
    }
};

有关详细信息,你可以看到关于使用凌空此伟大github上。

编辑:的 我刚才看到了这一点,并希望再添加一些code,如果你需要的是后添加的数据,而不是在URL中的信息。

I just now saw this, and wanted to add some more code if what you need is to post data instead of adding the info in the url.

public Request post(String url, String username, String password, 
      Listener listener, ErrorListener errorListener) {
  JSONObject params = new JSONObject();
  params.put("user", username);
  params.put("pass", password);
  Request req = new Request(
     Method.POST,
     url,
     params.toString(),
     listener,
     errorListener
  );

  return req;
}