英文:
Cannot properly set retrofit header in Android
问题
我有一个可以在下面的图片中看到的标题,在Postman中正常工作:
但是我无法在Android中正确使用它。
到目前为止,我尝试复制的部分是 Authorization Bearer 部分是一个 @Header("Authorization") 字符串头:
Call<GPSData> call = apiService.askGPS("Authorization Bearer: " + value, gpsPost);
Call<GPSData> call = apiService.askGPS("Authorization: Bearer " + value, gpsPost);
Call<GPSData> call = apiService.askGPS("Authorization: Bearer: " + value, gpsPost);
但是它们都不起作用。
哪种是等同于在Postman中显示的头部的正确语法?
英文:
I've the header that can be seen on the following image properly working in Postman:
But I'm not able to use it properly in Android.
My attempts to replicate that so far have been the following Authorization Bearer part is a @Header("Authorization") String header:
Call<GPSData> call = apiService.askGPS("Authorization Bearer: " + value, gpsPost);
Call<GPSData> call = apiService.askGPS("Authorization: Bearer " + value, gpsPost);
Call<GPSData> call = apiService.askGPS("Authorization: Bearer: " + value, gpsPost);
But none of them work.
Which is the correct syntax for a header equivalent to the one shown in Postman?
答案1
得分: 1
不要将Authorization作为标头值发送,因为如果您在API服务调用参数中使用@Header("Authorization") String value
,它会由Retrofit处理,而应该像这样做。
Call<GPSData> call = apiService.askGPS("Bearer: " + value, gpsPost);
英文:
don't send Authorization as the header value as it handled by retrofit if you use @Header("Authorization") String value
in the api service call parameter, instead do something like this.
Call<GPSData> call = apiService.askGPS("Bearer: " + value, gpsPost);
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论