如何使用Volley进行POST请求

huangapple 未分类评论43阅读模式
英文:

How to use volley post request

问题

我将使用Volley获取数据

RequestQueue queue = Volley.newRequestQueue(SummaryPhoneActivity.this);
String url = "https://covid19storageservice.table.core.windows.net/COVID19Survey?sv=2019-02-02&ss=bfqt&srt=sco&sp=rwdlacup&se=2020-06-30T18:04:08Z&st=2020-03-30T10:04:08Z&spr=https&sig=Ei3Kcr6xT5e7znK4ebwx6%2FVS09Ia5pbD1lnWRBh6bm4%3D";
StringRequest stringRequest = new StringRequest(Request.Method.GET, url, new Response.Listener<String>() {
    @Override
    public void onResponse(String response) {
        Log.d("response:", response);
    }
}, new Response.ErrorListener() {
    @Override
    public void onErrorResponse(VolleyError error) {
        Log.d("error:", error.toString());
    }
}) {
    @Override
    public Map<String, String> getHeaders() throws AuthFailureError {
        Map<String, String> params = new HashMap<String, String>();
        params.put("Content-Type", "application/json");
        return params;
    }
};

queue.add(stringRequest);

我在使用Volley时遇到了错误com.android.volley.ClientError
上述URL在Postman中可以正常工作
请问如何在上述情况下使用Volley提前感谢您的帮助
英文:

I am going to use volley to get data

RequestQueue queue = Volley.newRequestQueue(SummaryPhoneActivity.this);
    String url = &quot;https://covid19storageservice.table.core.windows.net/COVID19Survey?sv=2019-02-02&amp;ss=bfqt&amp;srt=sco&amp;sp=rwdlacup&amp;se=2020-06-30T18:04:08Z&amp;st=2020-03-30T10:04:08Z&amp;spr=https&amp;sig=Ei3Kcr6xT5e7znK4ebwx6%2FVS09Ia5pbD1lnWRBh6bm4%3D&quot;;
    StringRequest stringRequest = new StringRequest(Request.Method.GET, url, new Response.Listener&lt;String&gt;() {
        @Override
        public void onResponse(String response) {
            Log.d(&quot;response:&quot;, response);
        }
    }, new Response.ErrorListener() {
        @Override
        public void onErrorResponse(VolleyError error) {
            Log.d(&quot;error:&quot;, error.toString());
        }
    }){
        @Override
        public Map&lt;String, String&gt; getHeaders() throws AuthFailureError {
            Map&lt;String, String&gt; params = new HashMap&lt;String, String&gt;();
            params.put(&quot;Content-Type&quot;, &quot;application/json&quot;);
            return params;
        }
    };

    queue.add(stringRequest);

I can get error: com.android.volley.ClientError.
Above url is working on postman.
How can I use volley for above case. Thanks for your advance.

huangapple
  • 本文由 发表于 2020年4月3日 22:57:14
  • 转载请务必保留本文链接:https://java.coder-hub.com/61014650.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定