优步请求错误
Uber request error
我正在使用优步在我的应用程序中预订出租车。我得到价目表并成功通过身份验证以获取访问令牌。之后我尝试使用 request API.
预订出租车
我包括了request scope。
这是我调用请求的代码 API:
private void bookUBER(String selectedProductId,String token,double startLatitude,double startLongitude,
double endLatitude,double endLongitude) {
UberAPIClient.getSandBox().getRequest(token, selectedProductId,
startLatitude, startLongitude, endLatitude, endLongitude,
new UberCallback<UberModel>() {
@Override
public void success(UberModel uberModel, Response response) {
super.success(uberModel, response);
Log.e("uberModel", uberModel.toString());
Log.e("response", "" + response);
}
@Override
public void failure(RetrofitError error) {
Log.e("bookUBER error ", "" + error);
super.failure(error);
}
});
}
请求方法:
@POST("/requests")
void getRequest(@Header("Authorization") String authToken,
@Query("product_id") String productId,
@Query("start_latitude") double startLatitude,
@Query("start_longitude") double startLongitude,
@Query("end_latitude") double endLatitude,
@Query("end_longitude") double endLongitude,
Callback<UberModel> callback);
这是我的 logcat:
06-15 15:26:15.379: D/Retrofit(3142): <--- HTTP 406 https://sandbox-api.uber.com/v1/requests?product_id=fbc0033d-5a1a-4f01-964c-0e4ea56b6e7e&start_latitude=13.0497&start_longitude=80.2126&end_latitude=13.0827&end_longitude=80.2707 (2276ms)
06-15 15:26:15.379: D/Retrofit(3142): : HTTP/1.1 406 Not Acceptable
06-15 15:26:15.389: D/Retrofit(3142): Connection: keep-alive
06-15 15:26:15.389: D/Retrofit(3142): Content-Length: 164
06-15 15:26:15.389: D/Retrofit(3142): Content-Type: application/json
06-15 15:26:15.389: D/Retrofit(3142): Date: Mon, 15 Jun 2015 09:56:14 GMT
06-15 15:26:15.389: D/Retrofit(3142): Server: nginx
06-15 15:26:15.389: D/Retrofit(3142): Strict-Transport-Security: max-age=31536000; includeSubDomains; preload
06-15 15:26:15.389: D/Retrofit(3142): X-Android-Received-Millis: 1434362175394
06-15 15:26:15.389: D/Retrofit(3142): X-Android-Sent-Millis: 1434362174535
06-15 15:26:15.389: D/Retrofit(3142): X-Uber-App: uberex-sandbox
06-15 15:26:15.389: D/Retrofit(3142): X-XSS-Protection: 1; mode=block
06-15 15:26:15.389: D/Retrofit(3142): {"message":"Only request header `Content-Type: application\/json` is supported for this endpoint. Please check your request headers.","code":"invalid_content_type"}
06-15 15:26:15.389: D/Retrofit(3142): <--- END HTTP (164-byte body)
06-15 15:26:15.399: E/bookUBER error(3142): retrofit.RetrofitError: 406 Not Acceptable
06-15 15:26:15.399: W/System.err(3142): retrofit.RetrofitError: 406 Not Acceptable
06-15 15:26:15.409: W/System.err(3142): at retrofit.RestAdapter$RestHandler.invokeRequest(RestAdapter.java:388)
06-15 15:26:15.409: W/System.err(3142): at retrofit.RestAdapter$RestHandler.access0(RestAdapter.java:220)
06-15 15:26:15.409: W/System.err(3142): at retrofit.RestAdapter$RestHandler.obtainResponse(RestAdapter.java:278)
06-15 15:26:15.409: W/System.err(3142): at retrofit.CallbackRunnable.run(CallbackRunnable.java:42)
06-15 15:26:15.409: W/System.err(3142): at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1076)
06-15 15:26:15.409: W/System.err(3142): at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:569)
06-15 15:26:15.409: W/System.err(3142): at retrofit.Platform$Android.run(Platform.java:142)
06-15 15:26:15.409: W/System.err(3142): at java.lang.Thread.run(Thread.java:856)
我错过了什么吗?
提前致谢!
终于得到答案了。将来有人可能会从这个答案中受益。
我提到了 this.
我更改了请求方式:
@POST("/requests")
void getRequest(@Header("Authorization") String authToken,
@Body HashMap<String, String> obj,
Callback<UberModel> callback);
调用方法API:
private void bookUBER(String selectedProductId,String token,double startLatitude,double startLongitude,
double endLatitude,double endLongitude) {
HashMap<String, String> obj=new HashMap<String, String>();
obj.put("product_id", selectedProductId);
obj.put("start_latitude", String.valueOf(startLatitude));
obj.put("start_longitude", String.valueOf(startLongitude));
obj.put("end_latitude", String.valueOf(endLatitude));
obj.put("end_longitude", String.valueOf(endLongitude));
UberAPIClient.getSandBox().getRequest(token, obj,
new UberCallback<UberModel>() {
@Override
public void success(UberModel uberModel, Response response) {
super.success(uberModel, response);
Log.e("response", "" + response.toString());
}
@Override
public void failure(RetrofitError error) {
Log.e("uber price list error ", "" + error);
super.failure(error);
}
});
}
我正在使用优步在我的应用程序中预订出租车。我得到价目表并成功通过身份验证以获取访问令牌。之后我尝试使用 request API.
预订出租车我包括了request scope。
这是我调用请求的代码 API:
private void bookUBER(String selectedProductId,String token,double startLatitude,double startLongitude,
double endLatitude,double endLongitude) {
UberAPIClient.getSandBox().getRequest(token, selectedProductId,
startLatitude, startLongitude, endLatitude, endLongitude,
new UberCallback<UberModel>() {
@Override
public void success(UberModel uberModel, Response response) {
super.success(uberModel, response);
Log.e("uberModel", uberModel.toString());
Log.e("response", "" + response);
}
@Override
public void failure(RetrofitError error) {
Log.e("bookUBER error ", "" + error);
super.failure(error);
}
});
}
请求方法:
@POST("/requests")
void getRequest(@Header("Authorization") String authToken,
@Query("product_id") String productId,
@Query("start_latitude") double startLatitude,
@Query("start_longitude") double startLongitude,
@Query("end_latitude") double endLatitude,
@Query("end_longitude") double endLongitude,
Callback<UberModel> callback);
这是我的 logcat:
06-15 15:26:15.379: D/Retrofit(3142): <--- HTTP 406 https://sandbox-api.uber.com/v1/requests?product_id=fbc0033d-5a1a-4f01-964c-0e4ea56b6e7e&start_latitude=13.0497&start_longitude=80.2126&end_latitude=13.0827&end_longitude=80.2707 (2276ms)
06-15 15:26:15.379: D/Retrofit(3142): : HTTP/1.1 406 Not Acceptable
06-15 15:26:15.389: D/Retrofit(3142): Connection: keep-alive
06-15 15:26:15.389: D/Retrofit(3142): Content-Length: 164
06-15 15:26:15.389: D/Retrofit(3142): Content-Type: application/json
06-15 15:26:15.389: D/Retrofit(3142): Date: Mon, 15 Jun 2015 09:56:14 GMT
06-15 15:26:15.389: D/Retrofit(3142): Server: nginx
06-15 15:26:15.389: D/Retrofit(3142): Strict-Transport-Security: max-age=31536000; includeSubDomains; preload
06-15 15:26:15.389: D/Retrofit(3142): X-Android-Received-Millis: 1434362175394
06-15 15:26:15.389: D/Retrofit(3142): X-Android-Sent-Millis: 1434362174535
06-15 15:26:15.389: D/Retrofit(3142): X-Uber-App: uberex-sandbox
06-15 15:26:15.389: D/Retrofit(3142): X-XSS-Protection: 1; mode=block
06-15 15:26:15.389: D/Retrofit(3142): {"message":"Only request header `Content-Type: application\/json` is supported for this endpoint. Please check your request headers.","code":"invalid_content_type"}
06-15 15:26:15.389: D/Retrofit(3142): <--- END HTTP (164-byte body)
06-15 15:26:15.399: E/bookUBER error(3142): retrofit.RetrofitError: 406 Not Acceptable
06-15 15:26:15.399: W/System.err(3142): retrofit.RetrofitError: 406 Not Acceptable
06-15 15:26:15.409: W/System.err(3142): at retrofit.RestAdapter$RestHandler.invokeRequest(RestAdapter.java:388)
06-15 15:26:15.409: W/System.err(3142): at retrofit.RestAdapter$RestHandler.access0(RestAdapter.java:220)
06-15 15:26:15.409: W/System.err(3142): at retrofit.RestAdapter$RestHandler.obtainResponse(RestAdapter.java:278)
06-15 15:26:15.409: W/System.err(3142): at retrofit.CallbackRunnable.run(CallbackRunnable.java:42)
06-15 15:26:15.409: W/System.err(3142): at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1076)
06-15 15:26:15.409: W/System.err(3142): at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:569)
06-15 15:26:15.409: W/System.err(3142): at retrofit.Platform$Android.run(Platform.java:142)
06-15 15:26:15.409: W/System.err(3142): at java.lang.Thread.run(Thread.java:856)
我错过了什么吗?
提前致谢!
终于得到答案了。将来有人可能会从这个答案中受益。 我提到了 this.
我更改了请求方式:
@POST("/requests")
void getRequest(@Header("Authorization") String authToken,
@Body HashMap<String, String> obj,
Callback<UberModel> callback);
调用方法API:
private void bookUBER(String selectedProductId,String token,double startLatitude,double startLongitude,
double endLatitude,double endLongitude) {
HashMap<String, String> obj=new HashMap<String, String>();
obj.put("product_id", selectedProductId);
obj.put("start_latitude", String.valueOf(startLatitude));
obj.put("start_longitude", String.valueOf(startLongitude));
obj.put("end_latitude", String.valueOf(endLatitude));
obj.put("end_longitude", String.valueOf(endLongitude));
UberAPIClient.getSandBox().getRequest(token, obj,
new UberCallback<UberModel>() {
@Override
public void success(UberModel uberModel, Response response) {
super.success(uberModel, response);
Log.e("response", "" + response.toString());
}
@Override
public void failure(RetrofitError error) {
Log.e("uber price list error ", "" + error);
super.failure(error);
}
});
}