您可以使用Rest Client通过标头和URL调用请求。 我建议使用Volley或Retrofit来做到这一点。 下面是使用凌空一个例子:
RequestQueue queue = Volley.newRequestQueue(this);
String url = "https://developers.zomato.com/api/v2.1/search?&lat=27&lon=153";
JsonObjectRequest postRequest = new JsonObjectRequest(Request.Method.GET, url, null,
new Response.Listener<JSONObject>() {
@Override
public void onResponse(JSONObject response) {
// response
Log.d("Response", response.toString());
}
},
new Response.ErrorListener() {
@Override
public void onErrorResponse(VolleyError error) {
// TODO Auto-generated method stub
Log.d("ERROR", "error => " + error.toString());
}
}
) {
@Override
public Map<String, String> getHeaders() throws AuthFailureError {
Map<String, String> params = new HashMap<String, String>();
params.put("user-key", "55a1d18014dd0c0dac534c02598a3368");
params.put("Accept", "application/json");
return params;
}
};
queue.add(postRequest);
而且我已经得到了响应:
{"restaurants":[],"results_found":0,"results_shown":0,"results_start":0}