2

I was using the extension method ToHttpRequestMessage() from System.ServiceModel.Channels.MessageExtensionMethods

Source code for MessageExtensionMethods

I created a HttpRequestMessage from Message using the extension method in the above link. Then i used this HttpRequestMessage to be sent via HttpClient but I got the following exception

Cannot send a content-body with this verb-type

Cannot send a content-body with this verb-type

Does that mean that I cannot use the extension method or do I have to do anything specific for GET calls such as not setting the content-body?

Community
  • 1
  • 1
StackOverflowVeryHelpful
  • 2,347
  • 8
  • 34
  • 46
  • 2
    When you issue a `GET`, you **cannot have** a content body – marc_s Jan 28 '16 at 21:49
  • Are there any other headers as well which i should make sure that they are not part of GET calls. Also just to make sure that this restriction is for GET calls only and not other HTTP verbs – StackOverflowVeryHelpful Jan 28 '16 at 21:50
  • 3
    `GET` is intended to **retrieve/fetch** data - therefore a content body doesn't make any sense. Same goes for `DELETE`. You use a content body when you want to **send in** data to the service - such as in `POST`, `PUT` or `PATCH` situation. You need to read an intro to what the HTTP verbs are and what they mean and what options / restrictions they might have – marc_s Jan 28 '16 at 21:52
  • More on the methods here: https://www.w3.org/Protocols/rfc2616/rfc2616-sec9.html – Robert Bräutigam Jan 29 '16 at 07:25
  • @RobertBräutigam can't see patch there. Is is incomplete / outdated? – Andrew Savinykh Dec 12 '17 at 22:12
  • @AndrewSavinykh you're right, I linked to the old RFC. The new one is here: https://tools.ietf.org/html/rfc7231#section-4.3. Also the PATCH is in a different RFC here: https://tools.ietf.org/html/rfc5789. There are potentially other Methods defined in other RFCs (WebDAV comes to mind). Anyway the GET method has no defined semantics for body content, servers *may* reject a GET request with content. – Robert Bräutigam Dec 13 '17 at 07:33
  • 7
    It's not forbidden to send content body on a GET request. And there are applications that use it, like ElasticSearch. This is just another example of MS trying to be helpful but screwing things up. https://stackoverflow.com/questions/2064281/sending-post-data-with-get-request-valid – Andres Jan 15 '19 at 04:24
  • Does this answer your question? [Cannot send a content-body with this verb-type](https://stackoverflow.com/questions/3981564/cannot-send-a-content-body-with-this-verb-type) – underscore_d Aug 23 '21 at 12:15

0 Answers0