经过改造的发布请求在android中响应了一个错误的请求

问题描述 投票:1回答:1

我正在使用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);

我收到错误消息,告诉它一个错误的请求,如何解决此问题

android post http-headers retrofit
1个回答
0
投票

您可以尝试以下代码:

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);
© www.soinside.com 2019 - 2024. All rights reserved.