Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

how to post a http request from command line

Hi I need to post a request to aspx page within dos command line.. How can I do that ?

like image 383
TonyP Avatar asked Nov 25 '10 12:11

TonyP


People also ask

How send HTTP request Linux?

You can use either curl or wget command to send HTTP requests from UNIX or Linux operating system. Both commands allow you to send GET and POST requests, which means you can also call REST web services. I have a Java web application, which runs on Linux and exposes WebServices.

What is curl post command?

Curl is a popular command-line tool that allows you to send requests to the server, upload files, and submit web forms. Curl supports over 25+ protocols, including HTTP, HTTPS, SFTP, FTP, and has built-in support for web forms, SSL, user authentication, and HTTP cookies. Curl works on Linux, Windows, and Mac.


2 Answers

Create a .vbs file containing:

' Set your settings
    strFileURL = "http://localhost/index.aspx"
    strHDLocation = "stream.temp"

' Fetch the file
    Set objXMLHTTP = CreateObject("MSXML2.XMLHTTP")

    objXMLHTTP.open "GET", strFileURL, false
    objXMLHTTP.send()

If objXMLHTTP.Status = 200 Then
Set objADOStream = CreateObject("ADODB.Stream")
objADOStream.Open
objADOStream.Type = 1 'adTypeBinary

objADOStream.Write objXMLHTTP.ResponseBody
objADOStream.Position = 0    'Set the stream position to the start

Set objFSO = Createobject("Scripting.FileSystemObject")
If objFSO.Fileexists(strHDLocation) Then objFSO.DeleteFile strHDLocation

objADOStream.SaveToFile strHDLocation
objADOStream.Close
Set objADOStream = Nothing
End if

Set objXMLHTTP = Nothing

' Delete the temp file
objFSO.DeleteFile strHDLocation

Set objFSO = Nothing

Then execute using:

cscript.exe scriptname.vbs
like image 152
LikeableBias Avatar answered Oct 11 '22 10:10

LikeableBias


All of these answers require installing a windows feature or other program. Powershell is installed by default and can be run from the command line

powershell -command "Invoke-WebRequest -Uri %url% -Method POST"
like image 38
Neil Avatar answered Oct 11 '22 09:10

Neil