0

I am trying to construct an HTTP message like this

-------------------------------------------------------------
M-SEARCH * HTTP/1.1
HOST: 239.255.255.250:1982
MAN: "ssdp:discover"
ST: wifi_bulb
------------------------------------------------------------- 

But I cannot figure out how to change this part of a request

M-SEARCH * HTTP/1.1

It seems that HttpRequestMessage has its own pre-defined start line, that I can't change

Thanks!

  • 1
    That "thing" (M-SEARCH) is called the HTTP **verb** (aka "method"). As far as I can see in the docs, HttpRequestMessage has a constructor that takes a HttpMethod, and HttpMethod has a constructor that takes a string. *Looks like* that should work. – Heinzi Oct 06 '20 at 08:53
  • But I need start line to be exactly ```M-SEARCH * HTTP/1.1``` Right now I have something like ```Method: M-SEARCH, RequestUri: '239.255.255.250:1982', Version: 1.1, Content: , Headers: ``` – Fedor Sedov Oct 06 '20 at 09:18
  • "*Right now I have something like ...*" That looks like debug output, that is *not* what is actually transmitted via HTTP. – Heinzi Oct 06 '20 at 09:21
  • Is there a way to see what exactly will be transmitted? Without actually sending the message and using fiddler to view it? – Fedor Sedov Oct 06 '20 at 09:25
  • Good question, not that I know of. I have some additional information that might be helpful for your: `M-SEARCH` is the **verb/method**, `*` is the path to the requested resource, `Host`, etc. are **headers**. What might make your task a bit harder is the fact the the path to the requested resource and the `Host` header are usually auto-generated from the URL, i.e. `http://example.com/a.html` becomes `GET /a.html HTTP/1.1` `Host: example.com`. I'm not sure how much C# allows you to set those values independently. – Heinzi Oct 06 '20 at 09:37
  • Yep, that is the main thing stopping me right now Thanks for your help. I might try to do something like that in C++, where you have a bit more control over it – Fedor Sedov Oct 06 '20 at 16:42
  • Or use some lower level of the .NET framework (TcpClient). – Heinzi Oct 06 '20 at 17:07

0 Answers0