3

我正在使用 retrofit2 发送请求,但作为响应,我收到以下错误

响应{protocol=h2, code=404, message=, url= https://myurl/api/ }

在这里,我将我的基本网址传递给请求

静态最终字符串 BASE_URL = " https://myurl/ ";

这是我的控制器类。

private static Retrofit retrofit;

public static Retrofit getClient() {
    if (retrofit == null) {
        retrofit = new Retrofit.Builder()
                .baseUrl(BASE_URL)
                .addConverterFactory(GsonConverterFactory.create())
                .build();
    }
    return retrofit;
}

这是我的界面。在这里,我使用 map 传递带有参数和标题的正文

public interface AddProductApi {

    @FormUrlEncoded
    @POST("api/")
    Call<BodyOfAddPro> loadChanges(@FieldMap Map<String,String> body, 
@HeaderMap Map<String, String> header);
}

这是我的 api 调用函数,我正在传递参数以获取响应。我得到了上面显示的错误响应。

private void retroApiCall() {

    addProductApi = Controller.getClient().create(AddProductApi.class);

Map<String, String> addproductParams = new HashMap<String,String>();
addproductParams.put("UserID", sharedpreferences.getString("UserID", 
""));
    addproductParams.put("CategoryID", subsubCategoryID);

   addproductParams.put("ProductPrice",productPrice.getText().toString());
   addproductParams.put("DeliveryTime",Time.getText().toString();
   addproductParams.put("ProductType",itemCondition.getText().toString());
   addproductParams.put("OutOfStock", outofStock);
   addproductParams.put("IsActive", "1");


    Log.e("body",addproductParams.toString());

    Map<String, String> header = new HashMap<>();
    header.put("Verifytoken", sharedpreferences.getString("ApiToken",""));

    Log.e("header", header.toString());

    Call<BodyOfAddPro>call1
    =addProductApi.loadChanges(addproductParams,header);
    call1.enqueue(new Callback<BodyOfAddPro>() {
        @Override
        public void onResponse(Call<BodyOfAddPro> call, 
retrofit2.Response<BodyOfAddPro> response) {
            BodyOfAddPro loginResponse = response.body();

            Log.e("retroresponse", "Response 1 --> " + response);

        }

        @Override
        public void onFailure(Call<BodyOfAddPro> call, Throwable t) {
            Log.e("retroresponseerror", "Response 1 --> " + 
t.getMessage());

   }
    });

}

寻找答案。!

4

0 回答 0