为什么凌空不发送值?

时间:2019-02-27 22:17:08

标签: android android-volley

我是android开发的新手。我正在尝试使用凌空向服务器发送一些数据。但是它没有发送参数。请帮忙。服务器说未设置参数。我用php中的isset检查过。当我尝试从html表单发送数据时,它正在工作。但是截击没有发送参数。

public class MainActivity extends AppCompatActivity {

    EditText uname;
    EditText uotp;
    RequestQueue myqueue;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);

        uname = (EditText) findViewById(R.id.uname);
        uotp = (EditText) findViewById(R.id.uotp);

        myqueue = Volley.newRequestQueue(this);       
    }

    public void sendotp(View v)
    {
        String unameval = uname.getText().toString();
        if(unameval.matches(""))
        {
            Toast.makeText(getApplicationContext(), "Enter Phone Number", Toast.LENGTH_SHORT).show();
        }
        else
        {
            HashMap<String, String> params = new HashMap<>();
            params.put("phone", unameval);
            String myUrl = "http://privateurlhere";
            JsonObjectRequest request = new JsonObjectRequest(Request.Method.POST, myUrl, new JSONObject(params), new Response.Listener<JSONObject>() {
                @Override
                public void onResponse(JSONObject response) {
                    try {
                        String dispname = response.getString("stat");

                        Toast.makeText(getApplicationContext(), dispname, Toast.LENGTH_SHORT).show();
                    }
                    catch(JSONException e)
                    {
                        Toast.makeText(getApplicationContext(), e.getMessage(), Toast.LENGTH_SHORT).show();
                    }

                }
            }, new Response.ErrorListener() {
                @Override
                public void onErrorResponse(VolleyError error) {
                    Toast.makeText(getApplicationContext(),"Resp err" + error.toString(), Toast.LENGTH_SHORT).show();
                }
            });

            myqueue.add(request);
        }
    }
}

0 个答案:

没有答案
相关问题