【问题标题】:Error while processing request on Azure在 Azure 上处理请求时出错
【发布时间】:2018-04-06 22:07:53
【问题描述】:

我有一个与 Azure 后端连接的应用程序。我在 2 个月前创建了一个登录名和一些 api 调用。他们直到几天前都工作得很好,然后“有时”开始失败。
登录日志 onFailure 说:验证用户时出错
回调日志 onFailure 说:处理请求时出错
两者的原因都是:stream was reset: PROTOCOL_ERROR

这篇文章类似于this,但没有用。
这里有一些代码:

LoginFragment.java

    private void login(String email, String password){

    loginProgressBar.setVisibility(View.VISIBLE);

    try {

        JsonObject params = new JsonObject();
        params.addProperty("Username", email);
        params.addProperty("Password", password);
        ListenableFuture<MobileServiceUser> listenable = Client.logIn(getContext(), params);

        Futures.addCallback(listenable, new FutureCallback<MobileServiceUser>() {
            @Override
            public void onSuccess(MobileServiceUser mobileServiceUser) {
                loginProgressBar.setVisibility(View.GONE);

                SharedPreferences settings = getActivity().getSharedPreferences(Client.MS_USER,0);
                SharedPreferences.Editor editor = settings.edit();
                Client.clientId = mobileServiceUser.getUserId();
                Client.token = mobileServiceUser.getAuthenticationToken();
                editor.putString(Client.MS_USER_ID, Client.clientId);
                editor.putString(Client.MS_AUTH_TOKEN, Client.token);
                editor.apply();

                Client.getInstance(getContext()).setCurrentUser(mobileServiceUser);

                Intent i = new Intent(getContext(), MainActivity.class);
                startActivity(i);
            }

            @Override
            public void onFailure(Throwable t) {
                loginProgressBar.setVisibility(View.GONE);
                Throwable t2 = t.getCause();
                Throwable t3 = t2.getCause();
                Log.e("LoginFail", t.getMessage());
                Log.e("LoginFail", t2.getMessage());
                if(t3 != null){
                    Log.e("LoginFail", t3.getMessage());
                }
                Toast.makeText(getContext(), getResources().getString(R.string.bad_login), Toast.LENGTH_LONG).show();

            }
        }, MoreExecutors.directExecutor());
    } catch (MalformedURLException e) {
        e.printStackTrace();
    }
}


Client.java

public class Client {
public static final String MS_USER = "MS_USER";
public static final String MS_USER_ID = "MS_USER_ID";
public static final String MS_AUTH_TOKEN = "MS_AUTH_TOKEN";

public static String clientId;
public static String token;



private static MobileServiceClient instance = null;



public static MobileServiceClient getInstance(Context context) {

    if (instance ==null){
        try {
            instance = new MobileServiceClient(Env.AZURE_URL, context);
            instance.setAndroidHttpClientFactory(() -> {
                OkHttpClient client = new OkHttpClient();
                client.setReadTimeout(20, TimeUnit.SECONDS);
                client.setWriteTimeout(20, TimeUnit.SECONDS);
                return client;
            });
        } catch (MalformedURLException e) {
            e.printStackTrace();
        }

   } else{
        instance.setContext(context);
    }
    return instance;
}

public static ListenableFuture<MobileServiceUser> logIn(Context context, JsonObject parameters) throws MalformedURLException {
    String deviceID = "gcm:" + Settings.Secure.getString(context.getContentResolver(), Settings.Secure.ANDROID_ID);

    parameters.addProperty("device_id", deviceID);
    parameters.addProperty("device_dateTime", Env.DATE_FORMAT.format(new Date()));
    parameters.addProperty("device_timeZone", API.getTimezone());
    parameters.addProperty("device_language", Env.LANGUAGE);
    parameters.addProperty("app", Env.APP_NAME);

    return getInstance(context).login("auth", parameters);
}

public static  ListenableFuture<JsonElement> callApi(Context context, String apiName, JsonObject parameters, String httpMethod){

    if(httpMethod.equals("POST")){
        String deviceID = "gcm:" + Settings.Secure.getString(context.getContentResolver(), Settings.Secure.ANDROID_ID);

        parameters.addProperty("user_id", Client.clientId);
        parameters.addProperty("device_id", deviceID);
        parameters.addProperty("device_dateTime", Env.DATE_FORMAT.format(new Date()));
        parameters.addProperty("device_timeZone", API.getTimezone());
        parameters.addProperty("device_language", Env.LANGUAGE);
        parameters.addProperty("app", Env.APP_NAME);
        parameters.addProperty("role", "Patient");
        return getInstance(context).invokeApi(apiName, parameters, httpMethod, null);
    } else {
        return getInstance(context).invokeApi(apiName, null, httpMethod, null);
    }

}

【问题讨论】:

    标签: android azure azure-mobile-services azure-android-sdk


    【解决方案1】:

    这可能与 an issue in Azure App Service 相关,奇怪的是没有在公共 Azure 状态页面上报告。

    收到的影响 Azure 客户端的消息是(引用自上面的链接):

    从 2018 年 4 月 3 日 02:00 UTC 开始,您已被确定为 使用可能已收到连接失败的应用服务的客户 使用带有较旧 HTTP 客户端的 Android 应用程序时的通知或 使用跨站点脚本调用的桌面浏览器。工程师有 发现最近部署的问题并正在调查 缓解选项。遇到此问题的客户可以 通过将站点配置设置“http20Enabled”更新为自我缓解 通过 resources.azure.com 的错误。关于如何更新网站的说明 配置可以在这里找到: https://azure.microsoft.com/en-us/blog/azure-resource-explorer-a-new-tool-to-discover-the-azure-api/

    转到https://resources.azure.com/

    请确保您处于读/写模式,方法是单击 你名字的左边。

    找到受影响的站点并浏览到 Config > Web: https://resources.azure.com/subscriptions//resourceGroups//providers/Microsoft.Web/sites//config/web

    更改属性:“http20Enabled”:通过单击从 true 变为 false 在编辑属性中,更新为“false”,然后单击 PUT 保存 改变。

    如果您已尝试这些步骤并继续遇到问题 使用您的应用服务,请创建技术支持票证 进一步的故障排除:aka.ms/azsupt。此消息将在 7 内关闭 天。

    【讨论】:

    • 我都喜欢 azure 说的,但没有结果。可能与此有关,但我不知道可能是什么。如果您有其他建议,我会很高兴听到您的意见。无论如何,谢谢。
    猜你喜欢
    • 2016-09-07
    • 1970-01-01
    • 1970-01-01
    • 2014-04-29
    • 2015-07-06
    • 2020-03-15
    • 2017-06-17
    • 1970-01-01
    相关资源
    最近更新 更多