安卓开发网络测试(markedown)
2016-11-16 本文已影响16人
Kingcee
String url = "http://apis.baidu.com/apistore/mobilenumber/mobilenumber?phone=13*****7*57";
JsonObjectRequest request = new JsonObjectRequest(Method.GET, url, null, new Listener<JSONObject>() {
@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<String, String> getHeaders() throws AuthFailureError {
HashMap<String, String> headers = new HashMap<String, String>();
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;
}
}