Establishing a WebSocket connection using HttpClient / HttpResponseMessage

Viewed 131

Is it possible on .Net472 to initiate a WebSocket client connection using only HttpClient / HttpResponseMessage?

I've gotten to the point where I can lodge a request with appropriate headers and receive back the 101 reponse from the WS server. However, that's where it ends; I don't currently see a way to open up a WebSocket based on the response.

I would like to avoid ClientWebSocket. This seems seems to internally go through HttpWebResponse, which appears to special-case response streams for web socket requests (and creates a WebSocketConnectionStream for the response, based on which the WebSocket is then created). I've not found any such logic for HttpResponseMessages - but maybe I'm missing something.

(For context, the app I'm developing on has a whole lot of infrastructure around HttpClient - it would be atrocious having to try to squeeze in similar pipelines for yet another technology; so if i could at all leverage HttpClient, that would be much preferred)

0 Answers
Related