3

I am trying to make a request to an API in .NET Core 2. I have done it quite a few times without any problem, until now.

Maybe I just don't understand curl commands well enough, so here goes:

curl --include \
     --request GET \
     --header "Content-Type: application/json" \
     --data-binary "{\"company_id\": 1, \"timestamp\":\"1414421210832\", \"access_token\":\"K2Pxkwvx6-3PtW44zvEV\", \"signature\":\"db00061fa75f869c968f72d48449e457ae06959a\"}" \
http://api.bringg.com/partner_api/tasks

The above states that it is a GET command, yet it contains binary data which to me makes it a POST command. I see no way of adding HTTPContent to a GET command in .NET Core 2.

So, what is the equivalent of the above in .NET Core 2?

poke
  • 339,995
  • 66
  • 523
  • 574
EvilDonkey
  • 31
  • 1
  • 2
  • And you are sure this api doesn't also accept POST requests for this? – Evk Dec 09 '17 at 12:57
  • Note that servers are not supposed to interpret request bodies for GET requests. So it’s nonsensical to attempt to do that in the first place. – poke Dec 09 '17 at 13:04

1 Answers1

3

Primarily using WebRequest or HttpClient. Can you have a read through the following: https://docs.microsoft.com/en-us/aspnet/web-api/overview/advanced/calling-a-web-api-from-a-net-client

I use the above classes a lot when writing code that interacts with a Web API.

I don't know how to use "CURL" to do what you're asking, the aforementioned techniques is generally what's used when talking to a web API.

D. Foley
  • 1,014
  • 1
  • 9
  • 23
  • https://docs.microsoft.com/en-us/dotnet/csharp/tutorials/console-webapiclient this helped me – rupweb Sep 01 '21 at 08:39