Android 改装成功通过wifi返回数据,但在移动数据上失败

Android 改装成功通过wifi返回数据,但在移动数据上失败,android,retrofit2,Android,Retrofit2,我正在使用改型从web服务获取一些数据。 改型通过Wifi提供了成功响应,但每当我使用移动数据时,改型都会提供失败响应 Api类 public static final String BASE_URL = "http://www.jivansath.com/api/"; private static Retrofit retrofit = null; public static Retrofit getClient() { if (retrofit==null) {

我正在使用改型从web服务获取一些数据。 改型通过Wifi提供了成功响应,但每当我使用移动数据时,改型都会提供失败响应

Api类

public static final String BASE_URL = "http://www.jivansath.com/api/";
private static Retrofit retrofit = null;


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

public interface RestApis {


@GET("User/LoadAlert")
Call<AlertsPOJO> getAlert();

}
回应

public class Response {

@SerializedName("id")
@Expose
private Integer id;
@SerializedName("type")
@Expose
private Integer type;
@SerializedName("videourl")
@Expose
private String videourl;
@SerializedName("ImageURL")
@Expose
private String imageURL;
@SerializedName("Description")
@Expose
private String description;
@SerializedName("isactive")
@Expose
private Boolean isactive;

public Integer getId() {
    return id;
}

public void setId(Integer id) {
    this.id = id;
}

public Integer getType() {
    return type;
}

public void setType(Integer type) {
    this.type = type;
}

public String getVideourl() {
    return videourl;
}

public void setVideourl(String videourl) {
    this.videourl = videourl;
}

public String getImageURL() {
    return imageURL;
}

public void setImageURL(String imageURL) {
    this.imageURL = imageURL;
}

public String getDescription() {
    return description;
}

public void setDescription(String description) {
    this.description = description;
}

public Boolean getIsactive() {
    return isactive;
}

public void setIsactive(Boolean isactive) {
    this.isactive = isactive;
}

}}

有谁能告诉我为什么api在wifi上成功运行,而在移动数据上失败。

您可能没有INTERNET权限。 将此添加到清单文件

<uses-permission android:name="android.permission.INTERNET" />

使用改装代码配置客户端。遵循以下步骤

final OkHttpClient okHttpClient = new OkHttpClient.Builder()
    .connectTimeout(20, TimeUnit.SECONDS)
    .writeTimeout(20, TimeUnit.SECONDS)
    .readTimeout(30, TimeUnit.SECONDS)
    .build();
然后在您构建URL的地方调用此代码

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

将连接超时添加到最大值。这可能是移动电话连接不足的问题。

由于这是服务器端处理上的HTTP 202 vs 200问题,请尝试应用以下方法:
将网络配置文件添加到res文件夹

网络安全配置:

<network-security-config>
<domain-config cleartextTrafficPermitted="true">
    <domain includeSubdomains="true">your domain here</domain>
</domain-config>
<base-config cleartextTrafficPermitted="true">
    <trust-anchors>
        <certificates src="system" />
    </trust-anchors>
</base-config></network-security-config>

把你的两个都发出去logs@OmInfowaveDevelopersD/错误消息::无法解析主机“www.jivansath.com”:没有与主机名相关的地址我认为这是移动数据的问题,而不是与更新有关检查此行是否在您的清单中:-@SejpalPavan权限已存在无进展。我正在使用4g,但仍然存在无法解析主机“www.jivansath.com”的错误:没有与之关联的地址hostname@Wasif它们是ASP.NET Web服务吗是的,它们是ASP.NETServices@Wasif尝试先在POSTMAN上运行,然后在此处共享{“successcode”:202,“message”:“,”response:{“id”:1,“type”:5,“videourl”:“Uploads/Videos/apps/add1.mp4”,“ImageURL:”“说明”:“Hy新闻警报”,“isactive”:true}
public static Retrofit getClient() {
    if (retrofit==null) {
        retrofit = new Retrofit.Builder()
                .client(okHttpClient)
                .baseUrl(BASE_URL)
                .addConverterFactory(GsonConverterFactory.create())
                .build();
    }
    return retrofit;
}
<network-security-config>
<domain-config cleartextTrafficPermitted="true">
    <domain includeSubdomains="true">your domain here</domain>
</domain-config>
<base-config cleartextTrafficPermitted="true">
    <trust-anchors>
        <certificates src="system" />
    </trust-anchors>
</base-config></network-security-config>
android:networkSecurityConfig="@xml/network_security_config"