改造2中的响应{协议= http / 1.1,代码= 404,消息=未找到,url = https://sub.domain.com}

时间:2019-01-08 06:58:52

标签: android asp.net-web-api retrofit2 access-token iis-8

在IIS 7中,我们可以使用我们的应用程序成功获得令牌,但是当我们将应用程序服务器从IIS 7升级到IIS 8时,将从应用程序服务器返回以下错误。...

  

响应{协议= http / 1.1,代码= 404,消息=未找到,URL = {https://sub.domain.com}

我们的Retrofit 2 Singleton类如下

public class RetrofitSingleton {

public static final String BASE_URL = "https://sub.domain.com";

private static Retrofit retrofit = null;
private static Context sContext;
private static Retrofit sRetrofit;

public RetrofitSingleton() {
}

public synchronized static Retrofit getInstance(Context context) {
    sContext=context;
    if(sRetrofit==null){
        createRetrofit();
    }
    return sRetrofit;
}

private static void createRetrofit(){

    TrustManagerFactory trustManagerFactory = null;
    try {
        trustManagerFactory = TrustManagerFactory.getInstance(TrustManagerFactory.getDefaultAlgorithm());
    } catch (NoSuchAlgorithmException e) {
        e.printStackTrace();
    }
    try {
        trustManagerFactory.init((KeyStore) null);
    } catch (KeyStoreException e) {
        e.printStackTrace();
    }
    TrustManager[] trustManagers = trustManagerFactory.getTrustManagers();
    if (trustManagers.length != 1 || !(trustManagers[0] instanceof X509TrustManager)) {
        throw new IllegalStateException("Unexpected default trust managers:" + Arrays.toString(trustManagers));
    }
    X509TrustManager trustManager = (X509TrustManager) trustManagers[0];
    SSLContext sslContext = null;
    try {
        sslContext = SSLContext.getInstance("SSL");
    } catch (NoSuchAlgorithmException e) {
        e.printStackTrace();
    }
    try {
        sslContext.init(null, new TrustManager[] { trustManager }, null);
    } catch (KeyManagementException e) {
        e.printStackTrace();
    }
    SSLSocketFactory sslSocketFactory = sslContext.getSocketFactory();

    OkHttpClient okHttpClient= null;
    okHttpClient = new OkHttpClient.Builder()
            .sslSocketFactory(new TLSSocketFactory(),trustManager)
            .connectTimeout(2, TimeUnit.MINUTES)
            .readTimeout(2, TimeUnit.MINUTES)
            .writeTimeout(2, TimeUnit.MINUTES)
            //.sslSocketFactory(sslSocketFactory, trustManager)
            .followRedirects(false)
            .followSslRedirects(false)
            .retryOnConnectionFailure(false)
            .cache(null)//new Cache(sContext.getCacheDir(),10*1024*1024)
            .build();

    sRetrofit= new Retrofit.Builder()
            .client(okHttpClient)
            .baseUrl(BASE_URL)
            .addConverterFactory(GsonConverterFactory.create())
            .build();
}

在改进2 Api接口之后

@FormUrlEncoded
@POST("/Api/Token")
Call<TokenInfo> getTokenAccess(@Field("grant_type") String grantType);

我们无法理解,由于将IIS 7升级到IIS 8,需要更改配置/代码的任何位置。

谢谢。

注意:

 1. Using Postman we get token from our Asp.net Web api but from our android 
   app we cannot get token using retrofit 2.

 2. In IIS 7, our application & app works successfully.

2 个答案:

答案 0 :(得分:3)

您想知道,

  

我们无法理解,需要更改make的任何位置   由于将IIS 7升级到IIS 8而导致的配置/代码

答案是。由于升级IIS,您无需更改任何代码。问题是其他。

可能是与您的网络有关的问题。用Real IP正确检查您的子域轨道。查看并检查SSL配置和防火墙问题。这可能会解决您的问题。

答案 1 :(得分:2)

您的 RetrofitSingleton 类看起来不错。可能不是您的IIS问题。与SSL的IIS 7相比,IIS 8提供了更多的灵活性。就我而言,我遇到了IIS 8的SSL配置不完整的问题,请尝试使用IIS进行正确的SSL配置。按照给定的链接: https://www.sslsupportdesk.com/ssl-installation-instructions-for-windows-iis-8-and-8-5/