C# HTTP Body with GET method

后端 未结 3 581
一个人的身影
一个人的身影 2021-02-09 12:05

I\'m using an API that requires me to set the method to GET and include a message body. However when I try to do this I get the following error: \"Cannot send a content-body wi

相关标签:
3条回答
  • 2021-02-09 12:28

    It is entirely possible, but you have to use the newer HttpClient class: https://stackoverflow.com/a/47902348/70345

    0 讨论(0)
  • 2021-02-09 12:43

    It is not recommended to send content with a GET request. See this post for further details: HTTP GET with request body

    And this is what Roy Fielding has to say about the topic.

    0 讨论(0)
  • 2021-02-09 12:49

    What does one call an API that actively goes against REST? "HASTE"? "DISQUIET"?

    With a bit of luck they service just doesn't care what the verb is and the PHP code was just happening to use GET and hit the bug that the server didn't block it which is a pretty minor bug as long as it behaves correctly, and it'll be fine with POST.

    Failing that, your best bet is to see if they have an alternative method that either (if it's a reading request that naturally fits GET) accepts parameters in the URI with perhaps appropriate headers being used as per RFC 2616, or else can accept something through POST, GET etc.

    If that doesn't work, you'll have to build an HTTP client on top of TcpClient. Which would be pretty horrible.

    0 讨论(0)
提交回复
热议问题