VB.NET FCM代理407发行

发布于 2025-02-02 16:14:33 字数 2300 浏览 4 评论 0原文

我有一个基本的推送设置,它们的工作正常,没有代理。我试图添加代理设置,但无法设法使其正常工作。

我正在使用以下函数传递推送通知:

Public Function Send(ByVal title As String, body As String, token As String) As String
    Dim retval As String
    Try
        If FirebaseApp.DefaultInstance Is Nothing Then
            Dim defaultApp = FirebaseApp.Create(New AppOptions() With {
    .Credential = GoogleCredential.FromFile(Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "key.json")), .HttpClientFactory = New ProxySupportedHttpClientFactory()
    })
        End If
        Dim message As New Message
        With message
            .Webpush = New WebpushConfig
            With message.Webpush
                .Notification = New WebpushNotification
                With message.Webpush.Notification
                    .Title = title
                    .Body = body
                End With
            End With
        End With
        Dim messaging = FirebaseMessaging.DefaultInstance
        message.Token = token
        Dim result = messaging.SendAsync(message)
        retval = result.Result
    Catch ex As Exception
        retval = "ERROR: " & ex.Message
        If Not ex.InnerException Is Nothing Then
            If ex.InnerException.Message = "Requested entity was not found." Then
                retval = "ERROR: Requested token is not registered or invalid."
            Else
                retval &= "INNER Exception: " & ex.InnerException.Message
            End If
        End If
    End Try
    Return retval
End Function

并使用以下类进行代理集成:

Public Class ProxySupportedHttpClientFactory
Inherits HttpClientFactory


Protected Overrides Function CreateHandler(ByVal args As CreateHttpClientArgs) As HttpMessageHandler

    credentials = New NetworkCredential("1", "1")
    Dim proxy = New WebProxy("http://127.0.0.1:8888", True, Nothing, credentials)
    Dim webRequestHandler = New HttpClientHandler() With {
        .UseProxy = True,
        .Proxy = proxy,
        .UseCookies = False
    }
    Return webRequestHandler
End Function
End Class

但是当我尝试发送通知时,我会收到“远程服务器返回错误:(407)所需的代理身份验证”。行中的错误“ retval = result.result”。

代理配置可以与WebProxy一起使用简单的请求测试,但与FCM中的HTTPClientHandler一起使用。

编辑:我在凭据中使用key.json文件使用授权,文章说我也应该实现凭据连接的代理,但是我找不到将其与凭据零件集成的任何方法。

I have a basic setup for Push Delivery, they are working fine without proxy. I tried to add a proxy setting but couldn't manage to make it work.

I am using below function to deliver push notifications:

Public Function Send(ByVal title As String, body As String, token As String) As String
    Dim retval As String
    Try
        If FirebaseApp.DefaultInstance Is Nothing Then
            Dim defaultApp = FirebaseApp.Create(New AppOptions() With {
    .Credential = GoogleCredential.FromFile(Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "key.json")), .HttpClientFactory = New ProxySupportedHttpClientFactory()
    })
        End If
        Dim message As New Message
        With message
            .Webpush = New WebpushConfig
            With message.Webpush
                .Notification = New WebpushNotification
                With message.Webpush.Notification
                    .Title = title
                    .Body = body
                End With
            End With
        End With
        Dim messaging = FirebaseMessaging.DefaultInstance
        message.Token = token
        Dim result = messaging.SendAsync(message)
        retval = result.Result
    Catch ex As Exception
        retval = "ERROR: " & ex.Message
        If Not ex.InnerException Is Nothing Then
            If ex.InnerException.Message = "Requested entity was not found." Then
                retval = "ERROR: Requested token is not registered or invalid."
            Else
                retval &= "INNER Exception: " & ex.InnerException.Message
            End If
        End If
    End Try
    Return retval
End Function

And using below class for proxy integration:

Public Class ProxySupportedHttpClientFactory
Inherits HttpClientFactory


Protected Overrides Function CreateHandler(ByVal args As CreateHttpClientArgs) As HttpMessageHandler

    credentials = New NetworkCredential("1", "1")
    Dim proxy = New WebProxy("http://127.0.0.1:8888", True, Nothing, credentials)
    Dim webRequestHandler = New HttpClientHandler() With {
        .UseProxy = True,
        .Proxy = proxy,
        .UseCookies = False
    }
    Return webRequestHandler
End Function
End Class

But when I try to send a notification I get "The remote server returned an error: (407) Proxy Authentication Required." error in line "retval = result.Result".

Proxy configuration is working fine with WebProxy with a simple request test but not with HttpClientHandler in FCM.

EDIT: I am using authorization with key.json file in credentials, articles says i should implement proxy for credential connectivity too but i couldn't find any way to integrate it with credential part.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文