我正在使用https://docs.ngenius-payments.com/reference#hosted-payment-page在android中付款
标题:将这些标头添加到您的请求中(请注意,应在“入门”部分中将“ your_api_key”替换为服务帐户API密钥)。
标题值内容类型application / vnd.ni-identity.v1 + json
授权基础:your_api_key
正文/表单数据:将以下信息添加到您的请求的表单/正文中。
示例请求(正文):JSON格式{‘realmName’:‘ni’}
这些是标题和内容类型,我使用翻新方法创建了一个post方法
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);
我收到错误消息,告诉它一个错误的请求,如何解决此问题
您可以尝试以下代码:
String contentType = "application/vnd.ni-identity.v1+json";
String authorization = "Basic: "+apiKey;
JSONObject postParam = new JSONObject();
try {
postParam.put("realmName", "ni");
} catch (JSONException e) {
e.printStackTrace();
}
Call call = apiService.nGeniusAccessToken(contentType, authorization, postParam);