[服务器超出了通过Android Retrofit发布时的发布限制

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

我正在使用我的网站管理控制台(直接来自http://)在我的网站上发布长文章,没有问题。但是,当我想使用示例Android应用程序中的Retrifit将少量数据发布到我的网站时,我遇到数据限制错误

IIS 8.5详细错误-404.15-未找到

我必须将以下行添加到web.config中,错误消失了,但是我不确定这是否是最佳实践。

    <security>
        <requestFiltering>
            <requestLimits maxUrl="20000" maxQueryString="50000" />
        </requestFiltering>
    </security>

我正在使用Retrofit来发布数据(不是Get),如下所示:

public interface postData{
    @POST("collector/")
    Call<String> doPost(
        @Query("id") String id,
        @Query("r") String r
    );
}

有关更多详细信息,这是Retrofit实例的结构:

private static Retrofit retrofit;
private static final String BASE_URL = "https://www.example.com/app/";

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

脚注:改装onResponse返回NULL,并且未调用onFailure

android post web-config retrofit
1个回答
0
投票

我认为您最好将@Field与@Post一起使用>

public interface postData{
    @POST("collector/")
    Call<String> doPost(
        @Field("id") String id,
        @Field("r") String r
    );
}

Retrofit onResponse返回NULL并且未调用onFailure?

这可能是因为您收到的是有关错误正文而不是正文的响应。检查该打印或记录您的错误响应正文。

在您的onResponse()内部添加以下内容。应该是这样的。

if(response.body() == null){
Log.d("",response.errorBody())
}

我希望这会有所帮助。

© www.soinside.com 2019 - 2024. All rights reserved.