处理AzureMobile Apps HTTP2中的请求时出错错误
这个问题是针对Azure移动应用Android sdk最近的一个奇怪行为而提出的。几周来一切正常。现在,我的android客户端应用程序突然无法连接到我的web应用程序。土司上写着“处理请求时出错”。在Android Studio调试器中,我在SDK文件MobileServiceConnection.java中发现了异常处理AzureMobile Apps HTTP2中的请求时出错错误,azure,azure-mobile-services,azure-android-sdk,Azure,Azure Mobile Services,Azure Android Sdk,这个问题是针对Azure移动应用Android sdk最近的一个奇怪行为而提出的。几周来一切正常。现在,我的android客户端应用程序突然无法连接到我的web应用程序。土司上写着“处理请求时出错”。在Android Studio调试器中,我在SDK文件MobileServiceConnection.java中发现了异常 java.io.IOException: stream was reset: PROTOCOL_ERROR 在Azure Portal中,我的应用程序显示“健康”状态,但我可
java.io.IOException: stream was reset: PROTOCOL_ERROR
在Azure Portal中,我的应用程序显示“健康”状态,但我可以看到HTTP错误。请帮忙。
下面是我的代码,它工作正常,现在抛出错误
// Create the Mobile Service Client instance, using the provided mobile app URL.
try {
mClient = new MobileServiceClient(mMobileBackendUrl, activityContext).withFilter(
new ServiceFilter() {
@Override
public ListenableFuture<ServiceFilterResponse> handleRequest(ServiceFilterRequest request, NextServiceFilterCallback nextServiceFilter) {
// Get the request contents
String url = request.getUrl();
String content = request.getContent();
if (url != null) {
Log.d("Request URL:", url);
}
if (content != null) {
Log.d("Request Content:", content);
}
// Execute the next service filter in the chain
ListenableFuture<ServiceFilterResponse> responseFuture = nextServiceFilter.onNext(request);
Futures.addCallback(responseFuture, new FutureCallback<ServiceFilterResponse>() {
@Override
public void onFailure(Throwable exception) {
Log.d("Exception:", exception.getMessage());
}
@Override
public void onSuccess(ServiceFilterResponse response) {
if (response != null && response.getContent() != null) {
Log.d("Response Content:", response.getContent());
}
}
});
return responseFuture;
}
}
);
setAzureClient(mClient);
}catch(MalformedURLException e){
createAndShowDialog(new Exception("There was an error creating the Mobile Service. Verify the URL"), "Error");
}catch(Exception e){
createAndShowDialog("There was an error creating the Mobile Service. "+ e.toString(), "Error");
}
Toast.makeText(context, context.getString(R.string.online_authentication), Toast.LENGTH_SHORT).show();
authenticate();
}
private void authenticate() { // give access only to authenticated users via Google account authentication
HashMap<String, String> parameters = new HashMap<>();
parameters.put("access_type", "offline");//use "Refresh tokens"
//login with the Google provider. This will create a call to onActivityResult() method inside the context Activity, which will then call the onActivityResult() below.
mClient.login(MobileServiceAuthenticationProvider.Google, url_scheme_of_your_app, GOOGLE_LOGIN_REQUEST_CODE, parameters);
}
@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
super.onActivityResult(requestCode, resultCode, data);
// When request completes
if (requestCode == 1) {
try {
MobileServiceActivityResult result = mClient.onActivityResult(data);
if (result.isLoggedIn()) {
Toast.makeText(context, context.getString(R.string.azure_auth_login_success) /*+ " " + mClient.getCurrentUser().getUserId()*/, Toast.LENGTH_SHORT).show();
mUserId = mClient.getCurrentUser().getUserId();
} else {//>>>>THIS IS WHERE I AM GETTING THE ERROR
String errorMessage = result.getErrorMessage();
Toast.makeText(context, errorMessage, Toast.LENGTH_SHORT).show();// Error While processing request (it comes form the MobileServiceConnection.java file inside sdk)
}
}catch(Exception e){
Toast.makeText(context, e.toString(), Toast.LENGTH_LONG).show();
}
}
}
//使用提供的移动应用程序URL创建移动服务客户端实例。
试一试{
mClient=新的MobileServiceClient(mMobileBackendUrl,activityContext)。带筛选器(
新ServiceFilter(){
@凌驾
public ListenableFuture handleRequest(ServiceFilterRequest请求,NextServiceFilterCallback nextServiceFilter){
//获取请求内容
字符串url=request.getUrl();
String content=request.getContent();
如果(url!=null){
Log.d(“请求URL:,URL”);
}
如果(内容!=null){
Log.d(“请求内容:”,内容);
}
//执行链中的下一个服务过滤器
ListenableFuture responseFuture=nextServiceFilter.onNext(请求);
Futures.addCallback(responseFuture,newfuturecallback(){
@凌驾
失败时公共无效(可丢弃的例外){
Log.d(“异常:,异常.getMessage());
}
@凌驾
成功时公共无效(ServiceFilterResponse响应){
if(response!=null&&response.getContent()!=null){
Log.d(“响应内容:”,Response.getContent());
}
}
});
回报与未来;
}
}
);
setAzureClient(McClient);
}捕获(格式错误){
createAndShowDialog(新异常(“创建移动服务时出错。请验证URL”),“错误”);
}捕获(例外e){
createAndShowDialog(“创建移动服务时出错。”+e.toString(),“错误”);
}
Toast.makeText(context,context.getString(R.string.online_身份验证),Toast.LENGTH_SHORT.show();
验证();
}
private void authenticate(){//仅允许通过Google帐户身份验证的用户访问
HashMap参数=新的HashMap();
parameters.put(“访问类型”、“脱机”);//使用“刷新令牌”
//使用Google提供程序登录。这将在上下文活动中创建对onActivityResult()方法的调用,然后调用下面的onActivityResult()。
mClient.login(MobileServiceAuthenticationProvider.Google、您的应用程序的url\u方案\u、Google\u登录\u请求\u代码、参数);
}
@凌驾
受保护的void onActivityResult(int请求代码、int结果代码、意图数据){
super.onActivityResult(请求代码、结果代码、数据);
//当请求完成时
if(requestCode==1){
试一试{
MobileServiceActivityResult结果=mClient.onActivityResult(数据);
if(result.isLoggedIn()){
Toast.makeText(context,context.getString(R.string.azure_auth\u login\u success)/*+“”+mClient.getCurrentUser().getUserId()*/,Toast.LENGTH\u SHORT).show();
mUserId=mClient.getCurrentUser().getUserId();
}否则{/>>>>这就是我得到错误的地方
字符串errorMessage=result.getErrorMessage();
Toast.makeText(context,errorMessage,Toast.LENGTH_SHORT).show();//处理请求时出错(它来自sdk中的MobileServiceConnection.java文件)
}
}捕获(例外e){
Toast.makeText(上下文,例如toString(),Toast.LENGTH_LONG).show();
}
}
}
我自己找到了答案。此错误是由于Azure应用程序服务HTTP2连接问题造成的。这与应用程序代码无关。对于任何面临同样问题的人来说,以下是解决方案
我自己找到了答案。此错误是由于Azure应用程序服务HTTP2连接问题造成的。这与应用程序代码无关。对于任何面临同样问题的人来说,以下是解决方案
我建议您在Android项目的Android选项(tab Advanced)中将“HttpClientHandler”更改为“AndroidClientHandler”,看看是否有帮助。另外,请重新启动应用程序并重试。你能分享你得到的HTTP错误代码吗?此外,您还可以查看此GitHub链接:@谢谢你的回复。在哪里可以找到这个选项?我正在使用Android Studio和Azure门户。@SwikrutiBose已更新