Search code examples
windowsrestcmd

CMD send request to API


How could I send an HTTP request via Windows CMD to a remote API? For example

http://example.com/api/1

would return a JSON object.

I've seen some useful tools like cURL for windows, but if its possible I'd like to avoid installing any 3rd party software for this. In addition, what I'd like is sending the request, and save the response as a .txt file (call it resp.txt)


Solution

  • I know in powershell , the better window's command line tool, you could do the following.

    $client = new-object System.Net.WebClient
    $client.DownloadFile("http://example.com/anything.here", "C:\tmp\FROMNET.txt")
    

    In command line , I think it is not possible unless you install a 3rd party tool