我正在使用流式方法来模拟服务器和客户端之间的实时通信。当我直接从 web api 获取流时它工作正常。但是当我尝试通过 azure api 管理接收消息时,它会返回最后约 20 分钟的消息包。这是web api方法:
[HttpGet]
[Route("subscribe/{subscription}")]
public HttpResponseMessage Subscribe(string subscription)
{
PushStreamContent eventStream = new PushStreamContent(delegate (Stream stream, HttpContent content, TransportContext context)
{
Subscribe(subscription, stream);
}, new MediaTypeHeaderValue("text/event-stream"));
HttpResponseMessage message = Request.CreateResponse(HttpStatusCode.OK);
message.Content = eventStream;
return message;
}
为了获得流,我从 google chrome 控制台发送 XMLHttpRequest:
var request = new XMLHttpRequest()
request.open('get', 'https://{api}.azure-api.net/subscribe/hi', true)
request.setRequestHeader('Ocp-Apim-Subscription-Key','{subscription_key}')
request.onabort = function() { console.log('abort') }
request.onerror = function() { console.log('error') }
request.onprogress = function(e) { console.log(e) }
request.onload = function() { console.log('done') }
request.send()
那么是否可以以某种方式配置 azure API 管理以在流 Flush() 上返回消息?