✅ Sending an HTTP GET request with a JSON body and then reading it in the .NET Core Web Server
I have already tried this (these) StackOverflow solution: https://stackoverflow.com/questions/61004264/how-can-i-send-a-get-request-with-json-body
https://stackoverflow.com/questions/43421126/how-to-use-httpclient-to-send-content-in-body-of-get-request
Stack Overflow
How can I send a GET request with JSON body?
Is there any way at all that I can send a GET request with a JSON body using C#? I am making a call to an API to retrieve a list of items using a GET request, but I have to pass the customer_id in ...
Stack Overflow
How to use HttpClient to send content in body of GET request?
Currently to send a parameterized GET request to an API interface I am writing the following code:
api/master/city/filter?cityid=1&citycode='ny'
But I see that there is a limit on the URL leng...
49 Replies
Are you getting any errors? What issues are you having?
as a side note: what u are doing is essentially UB
The GET HTTP method requests a representation of the specified resource. Requests using GET should only be used to request data and shouldn't contain a body.
Note: The semantics of sending a message body in GET requests are undefined. Some servers may reject the request with a 4XX client error response.(source) so if u have control over both the client and the server/endpoint u should design it in another way
i do have control over it but this is for school and I have to do it like this. yes its not how u should but thats the point my prof wants me to figure out how to make it work.
then ⤴️ is the important stuff
Just doesnt work (404 just like how @cap5lut described it would be).
the server seems to be rejecting the request nothing is going through.
by ".NET Core Web Server" i assume ASP.NET Core?
yes
and no inbetween web server that works as reverse proxy like IIS, nginx, etc?
sorry i dont understand?
I am launching the web server through IIS express if thats what u mean?
so basically u just start u asp.net core web api/web app project to get the server to run right?
yes
well, u run it through iis, that could be already be an issue
how so
a reverse proxy basically delegates incoming requests to asp.net core, now u have 2 points where the request could be stopped
i do have other endpoints that use get/post/delete etc and they all work btw
tbh i dont even know what that means
or atleast not enough to debug
and figure out where the issue is happening
how would I go about figuring it out?
think of it as a man in the middle, the client talks to the iis express, the iis express talks to the asp.net core application, etc
how would i be able to figure out if its the application or the iis express that is at fault?
do u see in the logs the incoming request?
(the easiest would probably be to start the asp.net core project as stand alone process without iis express)
sorry i really dont understand. ive just been using postman and curl command to send requests so far with iis express being how it is getting launched
i assume u r using visual studio and i cant check there how to start it that way, because i am using jetbrains rider.
but essentially u could open the terminal, go to the project folder and execute
dotnet run
and it should start as standalone process without iis expressok holdup let me try that
you probably will have to set up HTTP logging
ahh
ok
but yeah when i do that im getting smth like this

yeah thats the normal logging ur application does
these logs look fine
I was just using console writeline inside the endpoints to see if its getting reached for now but it wasnt getting printed in output but i see thats not a good way to debug since the issue could be somewhere else
so first of all check now, if u can get it to work with either
https://localhost:5001/<your-endpoint>
or http://localhost:5000/<your-endpoint>
if it now works, the problem was the iis express for surenope doesnt work when i use postman
even the ones that did work before dont work
can u show me the url of an endpoint that worked previously?
says it could not send request error is socket hang up
yeah holdup
(quick afk for ~4-5min)
yeah no worries but for exmaple i had a post request like this with body that had "UserFour" in it
ill be back too igtg rn but thanks for the help and thanks in advance for any further help
try using https and change the port to what it says in the logs
so
https://localhost:5001/Api/User/new
the weird thing is actually that u get a 404 after all,
from various online resources (cant test it right now locally), it should be either a 400 response code (bad request),
or ur model binding simply wouldnt work
i have to stick to http
idk but yeah it says 404 not found
so does what SleepWellPupper mentioned work?
im supposed to stick to http not use https
the important point is that the port changed
http://localhost:53415/Api/User/new
was the old URI
so the endpoint is /Api/User/new
and the old base address was localhost:53415
for HTTP
from the logs u showed earlier, u can see that the new base addresses are localhost:5001
for HTTPS and localhost:5000
for HTTP
so the new URI for that endpoint should be: http://localhost:5000/Api/User/new
oh shiy
yeah
it works
test it like that first with a GET request that doesnt need a body, simply to test if it works
yeah it works
let me try the one with json now
wait
it works now
but for both
iis express and without
im so confused
let me try with my console client now actually and see what happens
kk, ill take a quick ciggy break
uh shit idk whats happening im getting build errors. it worked the first time but its not working now and i tried cleaning. chats saying its cuz the server is still running in background or hung so imma look into that
yeah it def is
alrighty everythung works now
thank u
idk how or why it changed
did u close the process u started via
dotnet run
?nope thats why
i killed it now
and iis express also works
im so confused why its working now
i dont have enough information to tell ya why it works 😂
postman i think typo was why but then still idk how my client side code didnt work because it works now
yeah fair enough and honestly as long as it works im happy lol
that 404 might be a hint that u were still running an old version, where that endpoint simply didnt exist yet.
because it doesnt make sense to respond with that status code
anyway, if ur problem is solved and u dont have any questions left, please mark this thread as that by $close ing it
If you have no further questions, please use /close to mark the forum thread as answered