0
我试图创建使用改型与一个键 - 值(&
分隔)的有效负载和简单的用户认证的请求,因为它可以在下面的curl
命令来完成:改造POST请求与URL编码主体和用户认证
curl -X POST -d "grant_type=refresh_token&refresh_token=<refresh_token>" -u"<client_id>:<client_secret>" http://localhost:8000/o/token/
如何在提供上述数据的改造中创建请求?如果使用的话,我需要接口方法和RequestBody
的创建。
UPDATE:
我用下面的代码
接口方法的定义:
@POST("/o/token/")
Observable<ServerToken> refreshAccessToken(@Header("Authorization") String auth, @Body RequestBody tokens);
调用实现:
RequestBody body = new FormEncodingBuilder()
.add("grant_type", "refresh_token")
.add("refresh_token", serverToken.refresh_token)
.build();
String auth = Credentials.basic("<client_id>", "<client_secret>");
mTokenApi.refreshAccessToken(auth, body)
但是我得到一个Content-Type: application/json
在请求和一个空的请求正文。
我该如何解决这个问题?
你面临什么问题? – Jonathan
@Jonathan更新了问题。谢谢 :) – vedant1811