Reputation: 1442
GET /server HTTP/1.1
Upgrade: WebSocket
Connection: Upgrade
Host: localhost:8181
Origin: http://localhost:8080
Sec-WebSocket-Key1: 42100 1 W5V X170y ER
Sec-WebSocket-Key2: ~\\ 8 I4ms;34 l`1j5 V2h0
Q??6QK?
Im receiving the above message and using c# to extract the last set of caracters (Q??6QK?) using the following Regex:
Regex.Match(message, "\r\n\r\n(?<value>.*?)$", options).Groups["value"].Value;
But the result of the Regex is return the string terminator caracter like this:
Q??6QK?\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0
Why? What is wrong?
Upvotes: 2
Views: 1999
Reputation: 27933
Your string contains nulls at the end. The problem is in the string you pass to the regex engine, not the regex engine itself.
Perhaps you can post the code that created the string. You are probably reading a little too much out of a byte[].
Upvotes: 1
Reputation: 10071
Those nulls are probably present in the response. Does the server specify a content-length?
Is there a reason you're not using an HTTP client to read from an HTTP service? You'll end up writing a lot of boilerplate (do do with connection failures and so on) that you could just let a library deal with for you.
Upvotes: 0