安卓开发网络测试(markedown)

String url = "http://apis.baidu.com/apistore/mobilenumber/mobilenumber?phone=13*****7*57";
JsonObjectRequest request = new JsonObjectRequest(Method.GET, url, null, new Listener() {
    @Override
    public void onResponse(JSONObject response) {
        Log.d(TAG, "查询成功:" + response);
        Toast.makeText(getApplicationContext(), "查询结果成功", Toast.LENGTH_SHORT).show();
    }
}, new ErrorListener() {
    @Override
    public void onErrorResponse(VolleyError error) {
        Log.d(TAG, "查询失败:" + error);
        Toast.makeText(getApplicationContext(), "查询失败", Toast.LENGTH_SHORT).show();
    }
}) {
    @Override
    public Map getHeaders() throws AuthFailureError {
        HashMap headers = new HashMap();
        headers.put("apikey", "[baidukey]");
        return headers;
    }
};
request.setTag("phoneGet");
UserLocalApplication.getHttpQueue().add(request);
public class UserLocalApplication extends Application  {
    public static RequestQueue requestQueue;//

    @Override
    public void onCreate() {
        super.onCreate();
        requestQueue = Volley.newRequestQueue(getApplicationContext());
    }

    public  static  RequestQueue getHttpQueue(){
        return requestQueue;
    }
}

你可能感兴趣的:(安卓开发网络测试(markedown))