【问题标题】:Volley library not working while posting the data to MVC Web Api将数据发布到 MVC Web Api 时 Volley 库无法正常工作
【发布时间】:2015-11-07 11:57:37
【问题描述】:

我正在尝试使用“Volley Library”将数据发布到 MVC WebApi。

您可以在此处找到 api 详细信息: http://mzrokz.somee.com/Help/Api/POST-api-LeadNowAppToCore-AddCustomer_firstname

如果成功,它将返回“1”。但是现在当我尝试发布它时会返回此异常

BasicNetwork.performRequest: Unexpected response code 404. 

这是我到目前为止所尝试的。

RequestQueue queue = Volley.newRequestQueue(LeadNowAddUser.this);
        StringRequest sr = new StringRequest(Request.Method.POST,"http://mzrokz.somee.com/api/LeadNowAppToCore/AddCustomer", new Response.Listener<String>() {
            @Override
            public void onResponse(String response) {

                Log.e("response",response);
            }
        }, new Response.ErrorListener() {
            @Override
            public void onErrorResponse(VolleyError error) {

            }
        }){
            @Override
            protected Map<String,String> getParams(){
                Map<String,String> params = new HashMap<String, String>();
                params.put("firstName","ankur");

                return params;
            }


        };

        queue.add(sr);

请帮助我。提前致谢。

【问题讨论】:

  • 您试图在不发送参数的情况下添加 custqomer?您做得不好,您必须在 gerParams() 中覆盖 getBody
  • @MaxPinto: 404 resp code is NOT FOUND, not BAD REQUEST :)
  • 取决于服务器和api,但你是对的

标签: android http post android-volley


【解决方案1】:

我尝试在 chorme Browser 的扩展 Advanced Rest 客户端中发布数据,但出现错误 404。 请检查您的网络服务

http://i.imgur.com/z70z4km.png

【讨论】:

    【解决方案2】:

    根据您链接中的文档,这是没有正文参数的 POST 请求。它使用 URL 参数,所以你只需要在你的应用程序中更新 URL 并删除getParams,请看下面的截图(我使用Postman)。希望这会有所帮助!

    【讨论】:

      猜你喜欢
      • 2021-09-21
      • 1970-01-01
      • 2019-02-06
      • 1970-01-01
      • 2017-10-10
      • 1970-01-01
      • 2023-02-16
      • 2021-04-17
      • 1970-01-01
      相关资源
      最近更新 更多