我正在尝试Location header url
从 skyscanner api url 获取轮询,http://partners.api.skyscanner.net/apiservices/pricing/v1.0
但我收到 500 Volley 服务器错误。谁能告诉我我做错了什么。我在 Chrome 的 Postman 中收到了标题响应。
public class MainActivity extends AppCompatActivity {
private static final String URL = "http://partners.api.skyscanner.net/apiservices/pricing/v1.0";
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
}
public void go(View v){
skyscannerpriceapi();
}
private void skyscannerpriceapi() {
Map<String, String> params = new HashMap<String, String>();
params.put("apiKey", "MY_API_KEY");
params.put("country", "US");
params.put("currency", "USD");
params.put("locale", "en-US");
params.put("originplace", "FLL");
params.put("destinationplace", "MCO");
params.put("outbounddate", "2016-07-20");
params.put("inbounddate", "2016-07-27");
params.put("locationschema", "iata");
params.put("cabinclass", "Economy");
params.put("adults", "1");
params.put("children", "0");
params.put("infants", "0");
params.put("groupPricing", "false");
JsonObjectRequest objectRequest = new JsonObjectRequest(
Request.Method.POST,
URL,
new JSONObject(params),
new Response.Listener<JSONObject>() {
@Override
public void onResponse(JSONObject response) {
Toast.makeText(MainActivity.this, response.toString(), Toast.LENGTH_SHORT).show();
}
},
new Response.ErrorListener() {
@Override
public void onErrorResponse(VolleyError error) {
Toast.makeText(MainActivity.this, error.toString(), Toast.LENGTH_SHORT).show();
}
}) {
@Override
public Map<String, String> getHeaders() throws AuthFailureError {
HashMap<String, String> headers = new HashMap<String, String>();
headers.put("Content-Type", "application/x-www-form-urlencoded");
headers.put("Accept", "application/json");
return headers;
}
};
RequestQueue requestQueue = Volley.newRequestQueue(getApplicationContext());
requestQueue.add(objectRequest);
}
}