gpt4 book ai didi

android - 在 Azure 上处理请求时出错

转载 作者:行者123 更新时间:2023-11-30 00:02:23 26 4
gpt4 key购买 nike

我有一个与 Azure 后端连接的应用程序。我在 2 个月前创建了一个登录名和一些 api 调用。他们工作得很好,直到几天前,然后它开始“有时”失败。
登录日志 onFailure 显示:验证用户时出错
回调日志 onFailure 显示:处理请求时出错
两者的原因都是:流已重置: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);
}

}

最佳答案

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

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

Starting at 02:00 UTC on 3 Apr 2018, you have been identified as a customer using App Services who may have received connection failure notifications when using Android apps with older HTTP clients or desktop browsers using cross-site scripting calls. Engineers have identified an issue with a recent deployment and are investigating mitigation options. Customers experiencing this issue can self-mitigate by updating the site config setting "http20Enabled" to false via resources.azure.com. Instructions on how to update site config can be found here: https://azure.microsoft.com/en-us/blog/azure-resource-explorer-a-new-tool-to-discover-the-azure-api/

Go to https://resources.azure.com/

Make sure you are in Read/Write mode by clicking in the option to the left of your name.

Find the affected site and browse to Config > Web: https://resources.azure.com/subscriptions//resourceGroups//providers/Microsoft.Web/sites//config/web

Change the property: "http20Enabled": from true to false by clicking in Edit properties, Update to “false” and then clicking PUT to save change.

If you have tried these steps and are continuing to experience issues with your App Service, please create a technical support ticket to further troubleshoot: aka.ms/azsupt. This message will be closed in 7 days.

关于android - 在 Azure 上处理请求时出错,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49690586/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com