使用Web服务URL的Volley Post请求失败

时间:2015-02-27 00:18:43

标签: android android-volley

我的网络服务中有一个URL响应请求:

我的rails应用程序中的

http://localhost:3000/setFavoriteSpecial/1/47/190/2充当web服务,方法为:

def setFavoriteSpecial
        setFavoriteSpecial = "INSERT INTO androidchatterdatabase.users_saved_campaigns(usersId,campaignId,cityLocationId,timePeriod,savedDt)
                              VALUES(" + params[:user_id].to_s + "," + params[:campaign_id].to_s + "," + params[:metro_id].to_s + "," + params[:time_period].to_s + ", NOW())"

        ActiveRecord::Base.connection.execute(setFavoriteSpecial)
    end

有路线:

  match '/setFavoriteSpecial/:user_id/:campaign_id/:metro_id/:time_period', to: 'requests#setFavoriteSpecial', via: 'get'

根据四个输入参数设置一个人喜欢的特殊。但是,凌空发布请求,传入正确的参数不会产生此方法的插入,而只是出错。

请求如下:

            String setFavoriteSpecial = "http://" + Global.getIpAddress() + ":3000/setFavoriteSpecial/";

            StringRequest postRequest = new StringRequest(Request.Method.POST, setFavoriteSpecial,
                    new Response.Listener<String>() {
                        @Override
                        public void onResponse(String response) {
                            // response
                            Log.d("Response", response);
                        }
                    },
                    new Response.ErrorListener() {
                        @Override
                        public void onErrorResponse(VolleyError error) {
                            // error
                            Log.d("Error.Response", error.toString());
                        }
                    }
            ) {
                @Override
                protected Map<String, String> getParams() {
                    Map<String, String> params = new HashMap<String, String>();
                    params.put("user_id", LoggingIn.userId);
                    params.put("campaign_id", specialId);
                    params.put("metro_id", "190");
                    params.put("time_period", "3");

                    return params;
                }
            };
            requestQueue.add(postRequest);

错误如下:

 E/Volley﹕ [190] BasicNetwork.performRequest: Unexpected response code 404 for http://192.168.1.122:3000/setFavoriteSpecial/2//109/3
 D/Error.Response﹕ com.android.volley.ServerError

为什么要为Volley工作赢得此设置?

0 个答案:

没有答案