无法向Github API发出POST请求

时间:2019-01-01 00:30:25

标签: android git rest android-volley github-api

我正在尝试对此URL进行POST请求:

https://api.github.com/search/repositories?q=created:%3E2018-12-29&sort=stars&order=desc

使用参数:'q','sort'和'order',但是我收到一条消息说'q'代码丢失。

Request parameters

Response message

使用POST方法在我的android凌空上也不起作用:

RequestQueue mQueue = Volley.newRequestQueue(this);

    StringRequest request = new StringRequest(Request.Method.POST,"https://api.github.com/search/repositories", new Response.Listener<String>() {
        @Override
        public void onResponse(String response) {
            Log.d("ANANAS","ONRESPONSE");
        }
    }, new Response.ErrorListener() {
        @Override
        public void onErrorResponse(VolleyError error) {
            Log.d("ANANAS","ONERROR");
            Log.d("ANANAS",error.getMessage());
        }
    }){
        @Override
        protected Map<String, String> getParams() {

            Map<String,String> params = new HashMap<String,String>();
            params.put("q","created:>2018-12-13");
            params.put("sort","stars");
            params.put("order","desc");
            return params;
        }
    };

    mQueue.add(request);

我想念什么?

1 个答案:

答案 0 :(得分:2)

您的参数很好,但是您应该使用Request.Method.GET,因为API将期待GET(请参见API docs)。

StringRequest request = new StringRequest(Request.Method.GET,"https://api.github.com/search/repositories"