NodeJS没有收到参数

时间:2019-01-20 15:30:03

标签: android api android-volley backend

我正在尝试通过齐射通过内部包含参数的方式向我的后端API发送帖子,但是后端没有收到任何内容

Android方法:

private void sendPayments() {
    RequestQueue requestQueue = Volley.newRequestQueue(PaymentActivity.this);

    StringRequest stringRequest = new StringRequest(Request.Method.POST, clientCheckout, new Response.Listener<String>() {
        @Override
        public void onResponse(String response) {
            Log.e(TAG, "onResponse: "+response);

            if(response.toString().contains("Successful")) {
                Log.e(TAG, "onResponse: Successful");
            } else {
                Log.e(TAG, "onResponse: Failed");
            }
        }
    }, new Response.ErrorListener() {
        @Override
        public void onErrorResponse(VolleyError error) {
            Log.e(TAG, "onErrorResponse: "+error);
        }
    })
    {
        @Override
        protected Map<String, String> getParams() throws AuthFailureError {
            if(paramHash == null)
                return  null;
            Map<String, String> params = new HashMap<>();
            for (String key: paramHash.keySet()) {
                params.put(key, paramHash.get(key));
            }
            Log.e(TAG, "getParams: "+params);
            return params;
        }

        @Override
        public Map<String, String> getHeaders() throws AuthFailureError {
            Map<String, String> params = new HashMap<>();
            params.put("Content-Type", "application/x-www-form-urlencoded");
            return params;
        }
    };
    requestQueue.add(stringRequest);
}

这是后端代码:

 router.post('/checkout', (req, res, next) => {
  var url_parts = url.parse(req.url, true);
  var query = url_parts.query;

  const nonceFromTheClient = query.nonce;
  console.log(req.params);
  console.log(req.query);
  console.log(query);

  gateway.transaction.sale({
  amount: "10.00",
  paymentMethodNonce: nonceFromTheClient,
  options: {
    submitForSettlement: true
  }
}, function (err, result) {
  if(err) {
    console.log(err);
  } else {
    console.log(result);
  }
});
})

后端中的所有日志均不返回任何内容!但是Log.e(TAG, "getParams: "+params);记录数据,因此数据存在,但我不知道它是否已发送并且后端无法读取它或不是从头开始发送

0 个答案:

没有答案