android - Android将授权标头添加到grpc Stub,错误:“onError:io.grpc.StatusRuntimeException:UNAVAILABLE”
问题描述
我无法使用成功添加标题
// create a custom header
val header: io.grpc.Metadata = io.grpc.Metadata()
val auth: io.grpc.Metadata.Key<String> = io.grpc.Metadata.Key.of("authorization", io.grpc.Metadata.ASCII_STRING_MARSHALLER)header.put(auth, "barer "+ AWSMobileClient.getInstance().tokens.idToken.tokenString);
Stub = io.grpc.stub.MetadataUtils.attachHeaders(Stub, header)
正如Android建议的那样如何在grpc客户端中添加自定义标头?.
我得到: onError: io.grpc.StatusRuntimeException: UNAVAILABLE
在IOS中,我能够使用:
let authToken = "\(AWSCognitoUserPoolsSignInProvider.sharedInstance().getUserPool().token().result ?? "")"
let httpHeader: [(String, String)] = [("Authorization", authToken)]
let header = HPACKHeaders(httpHeader)
callOptions = CallOptions(customMetadata: header, timeLimit: .none, messageEncoding: .disabled , requestIDProvider: .none, requestIDHeader: nil, cacheable: false)
let req = Cilix_Api_GetVersionRequest()
let request = self.client?.getVersion(req, callOptions: callOptions)
任何建议将被认真考虑
解决方案
问题不在android客户端或标题的附加中。
ALPN 在后端被禁用,需要强制执行才能使 android 客户端正常工作。
我将编辑问题的标题以包含错误消息:
onError: io.grpc.StatusRuntimeException: UNAVAILABLE
以防有人遇到错误但没有尝试添加标题。
推荐阅读
- css - 我的浮动图标位于我网站内容的后面
- python - 多处理时如何解决“无法序列化'_io.BufferedReader'对象”?
- asp.net - 如何使用 parsley.js 验证 TreeView?
- git - 如何列出作者插入的行,不包括文件?
- c# - 数据库中的某些属性在具有值时为空
- firebase - 何时在 noSQL 中复制数据?
- html - 如何创建多步骤表单
- reactjs - React TypeError:“这是未定义的”,函数调用中的函数不起作用
- mysql - SQL 查询:显示多个数据和总订单值
- php - [PHP][LARAVEL]“找不到类 'App\User'”,但显然有 'use App\User;' 在代码中