0

When searching SO regarding the topic Http GET with request body/parameters it often ends in a debate regarding whether to do it or not - even though the OP simply asks for examples.

Now I am asking again if anyone does have some simple examples of how to do it, looking away from the fact that some (old) systems might not be able to process the request.

Ian Kemp has shown, that it can be done here: Possible for HttpClient to send content or body for GET request?

But honestly my coding "skills" aren't good enough to understand his example - is there a more simple example out there?

Where the body only contains fx 1 parameter, that I want to check on. (No headers at all - since the headers are sliced off by the PaaS).

UPDATE - clarifying what I don't understand regarding Ian's example:

Content = new StringContent("some JSON", Encoding.UTF8, ContentType.Json),

I don't understand, how "some JSON" is being passed. Where does the Get-method fetch the JSON from? Is it from the URL, that is provided in the line above it?

I want to check the JSON/body to check a parameters value, but can't figure out from Ian's example, how that is possible when I don't understand the "some JSON"-part..

Matt Qafouri
  • 1,449
  • 2
  • 12
  • 26
nelion
  • 1,712
  • 4
  • 17
  • 37
  • 1
    Maybe put the part of code you don't understand. It's quite simple and well explained in the linked answer... – pwas Jul 26 '19 at 06:31
  • also as you said _"some (**old**) systems"_ - this is not a question of "old" or "new" systems. this case (posting a body within a GET request) you are just using undocumented features of HTTP protocol. Maybe tomorrow this will be strictly prohibited. Maybe not. – vasily.sib Jul 26 '19 at 06:40
  • @pwas thank you - I have updated the question. – nelion Jul 26 '19 at 06:58
  • @vasily.sib Ah okay. From what I've understood from other SO-discussions/questions, then some systems cant handle the body inside GET. Postman couldn't before, but can now and somehow elasticsearch has created a GET with a body, but has a backup-plan with a POST, if the program/client shouldn't be able to handle the GET with the body. – nelion Jul 26 '19 at 06:59
  • 1
    In order to supply data to a GET request, I suggest serialising the data as query string; thereby delivering "content" over a GET request - in a manner which is supported in pretty much any HTTP 1.1 implementation – ne1410s Jul 26 '19 at 07:07
  • @ne1410s - Okay, I think I get it now. I will create a model, containing 1 param, which I will create a json-body from, deserialize, validate parameter and then go on from there. Thanks. – nelion Jul 26 '19 at 08:02
  • @ne1410s Hmm.. I still can't figure out how to get the data from the JSON object, without putting it in the query/parameter inside the GET-method. The model is created, I know how to serialize it, but how to I check it before those steps.. – nelion Jul 26 '19 at 08:48
  • The data would live in the URL itself. e.g. https://tempurl.com/items?id=2&name=tester (As you can see, this is great for flat data structures, but may become problematic with nesting structures). Also, the strings would have to be URL encoded, etc. – ne1410s Jul 26 '19 at 08:55

0 Answers0