Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/400.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/spring-mvc/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java 如何在改型中使用JSON发送GET请求_Java_Android_Retrofit - Fatal编程技术网

Java 如何在改型中使用JSON发送GET请求

Java 如何在改型中使用JSON发送GET请求,java,android,retrofit,Java,Android,Retrofit,我想创建一个应用程序,将找到一个滑板车。我正在使用Bird(Scooter)api。我得到了一个Auth令牌,但是当我想用GET方法发送带有头的请求时,它会返回我的响应代码401,但是Auth令牌不是空的。请帮帮我 我的请求接口 公共接口ApiCallsInterface{ @标题({ “设备id:43ba174c-11f4-4918-9fcc-6d785cfc256e” ,“平台:android”,“内容类型:应用程序/json” }) @POST(“/user/login”) 调用getAu

我想创建一个应用程序,将找到一个滑板车。我正在使用Bird(Scooter)api。我得到了一个Auth令牌,但是当我想用GET方法发送带有头的请求时,它会返回我的响应代码
401
,但是Auth令牌不是空的。请帮帮我

我的请求接口

公共接口ApiCallsInterface{
@标题({
“设备id:43ba174c-11f4-4918-9fcc-6d785cfc256e”
,“平台:android”,“内容类型:应用程序/json”
})
@POST(“/user/login”)
调用getAuthToken(@Body-Map-params);
@标题({
“设备id:43ba174c-11f4-4918-9fcc-6d785cfc256e”,
“应用程序版本:3.0.5”
})
@获取(“/bird/附近?纬度=37.77184,经度=122.40910,半径=1000”)
调用getBirds(@Header(“Authorization”)字符串标记,@Header(“Location”)映射参数;}
我如何发送请求

Map requestParams=new HashMap();
请求参数put(“纬度”,纬度);
请求参数put(“经度”,lng);
请求参数put(“高度”、“500”);
请求参数put(“精度”、“100”);
请求参数put(“速度”、“-1”);
请求参数put(“标题”、“-1”);
getBirds(AUTH_令牌,requestParams).enqueue(新回调(){
@凌驾
公共void onResponse(调用、响应){
Log.d(标记“”+response.code());
}
@凌驾
失败时公共无效(调用调用,可丢弃的t){
}
});

请确保在api文档中的令牌之前添加“Bird”。

401请求需要用户身份验证

未正确添加标题这里是正确生成标题的指南

public interface ApiCallsInterface {

@Headers({
        "Device-id:43ba174c-11f4-4918-9fcc-6d785cfc256e"
        ,"Platform:android","Content-type:application/json"
})
@POST("/user/login")
Call<AuthResponseClass> getAuthToken(@Body Map<String, String> params);

@Headers({
        "Device-id:43ba174c-11f4-4918-9fcc-6d785cfc256e",
        "App-Version:3.0.5"
})
@GET("/bird/nearby?latitude=37.77184&longitude=-122.40910&radius=1000")
Call<BirdResponse> getBirds(@Header("Authorization") String token, @Header("Location") Map<String, String> params);}
Map<String, String> requestParams = new HashMap<>();
requestParams.put("latitude",lat);
requestParams.put("longitude",lng);
requestParams.put("altitude","500");
requestParams.put("accuracy","100");
requestParams.put("speed","-1");
requestParams.put("heading","-1");

apiCallsInterface.getBirds(AUTH_TOKEN,requestParams).enqueue(new Callback<BirdResponse>() {
    @Override
    public void onResponse(Call<BirdResponse> call, Response<BirdResponse> response) {
        Log.d(TAG,"" + response.code());
    }

    @Override
    public void onFailure(Call<BirdResponse> call, Throwable t) {

    }
});