【发布时间】:2020-07-07 13:08:51
【问题描述】:
我正在使用https://docs.ngenius-payments.com/reference#hosted-payment-page在android中付款
标题: 将这些标头添加到您的请求中(请注意,您应该将“your_api_key”替换为“入门”部分中的服务帐户 API 密钥)。
标题值 Content-Type application/vnd.ni-identity.v1+json
基本授权:your_api_key
正文/表格数据: 将以下信息添加到请求的表单/正文内容中。
示例请求(正文): JSON { ‘realmName’:‘你’ }
这些是标题和内容类型,我使用改造创建了一个发布方法
public static Retrofit getRetrofitClient() {
//If condition to ensure we don't create multiple retrofit instances in a single application
if (retrofit == null) {
//Defining the Retrofit using Builder
retrofit = new Retrofit.Builder()
.baseUrl(BASE_URL) //This is the only mandatory call on Builder object.
.addConverterFactory(GsonConverterFactory.create()) // Convertor library used to convert response into POJO
.build();
}
return retrofit;
}
我的api接口是
@POST("identity/auth/access-token")
Call<NgeniusPaymentAccessTokenModel> nGeniusAccessToken(@Header("content-type") String ContentType, @Header("authorization") String apiKey, @Body JsonObject object);
我叫它
JsonObject postParam = new JsonObject();
try {
postParam.addProperty("realmName", "ni");
} catch (Exception e) {
e.printStackTrace();
}
Call call = apiService.nGeniusAccessToken(contentType, "Basic "+apiKey, postParam);
我得到的响应是错误,告诉它一个错误的请求,如何解决这个问题
【问题讨论】:
-
您发送的请求正文不符合您后端的预期格式。请清除请求正文要求。
标签: android post http-headers retrofit