![](/img/trans.png)
[英]Existing authentication with ServiceStack ServerEventsClient
[英]404 not found error using ServiceStack ServerEventsClient with Pipedream SSE API
我使用Pipedream作为数据源,它通过 SSE API 提供事件数据。
按照此处的说明,我使用以下代码订阅 SSE:
var client = new ServerEventsClient("https://api.pipedream.com/sources/dc_mXugEA/sse")
{
EventStreamRequestFilter = req => req.AddBearerToken("[MYTOKEN]"),
OnMessage = message => Console.WriteLine(message.Json)
}.Start();
但是,我收到一条System.Net.WebException
其中包含消息“远程服务器返回错误:(404) 未找到”。
但是如果我直接使用HttpClient
,它就成功了:
var client = new HttpClient();
client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", "[MYTOKEN]");
using var reader = new StreamReader(await client.GetStreamAsync("https://api.pipedream.com/sources/dc_mXugEA/sse"));
while (!reader.EndOfStream)
{
Console.WriteLine($"Received message: {await reader.ReadLineAsync()}");
}
当然,我想使用ServerEventsClient
而不是HttpClient
来避免样板循环代码。 但是为什么ServerEventsClient
在这种情况下不起作用?
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.