Android凌空回复帖子回复

时间:2017-09-24 01:17:29

标签: c# android asp.net-web-api android-volley

我通过Anadroid Volley将我的用户名和密码发送到c#web api:

StringRequest stringRequest = new StringRequest(Request.Method.POST, URL,
            new Response.Listener<String>() {
                @Override
                public void onResponse(String response) {
                    try {
                        JSONObject jsonObject = new JSONObject(response);
                        String Response = jsonObject.getString("response");
                        Toast.makeText(getApplicationContext(), Response, Toast.LENGTH_LONG).show();
                    } catch (JSONException e) {
                        e.printStackTrace();
                    }

                    Toast.makeText(MainActivity.this, response, Toast.LENGTH_SHORT).show();
                }
            }, new Response.ErrorListener() {
        @Override
        public void onErrorResponse(VolleyError error) {
            Toast.makeText(getApplicationContext(), error.toString(), Toast.LENGTH_LONG).show();

        }
    }
    ) {
        @Override
        protected Map<String, String> getParams() throws AuthFailureError {
            Map<String, String> params = new HashMap<>();




            params.put("name", mail.getText().toString());
            params.put("email", password.getText().toString());


            return params;
        }
        @Override
        protected Response<String> parseNetworkResponse(NetworkResponse response) {
            String responseString = "";
            if (response != null) {

                responseString = String.valueOf(response.statusCode);
                if(response.statusCode != 200){
                    Intent ps = new Intent(getApplicationContext(), Pricipal.class);
                    startActivity(ps);
                }

            }

            return Response.success(responseString, HttpHeaderParser.parseCacheHeaders(response));
        }


    };
    stringRequest.setRetryPolicy(new RetryPolicy() {
        @Override
        public int getCurrentTimeout() {
            return 50000;
        }

        @Override
        public int getCurrentRetryCount() {
            return 50000;
        }

        @Override
        public void retry(VolleyError error) throws VolleyError {

        }
    });


    MySingleton.getInstance(getApplicationContext()).addTorequesteque(stringRequest);

如果用户存在,我想检查服务器。如果用户存在,我想打开一个新的意图。否则向用户显示Toast&#34;用户名或密码不正确&#34;。

服务器的响应是字符串:

public String Post([FromBody]Data values)
    {

        if(values.name == "malkibn")
       {

                    return "yes";
        }

                return "no";
    }

我想返回服务器的值&#34;是&#34; &安培; &#34;无&#34;

0 个答案:

没有答案