how to post a http request from command line

2019-03-20 02:46发布

问题:

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

回答1:

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


回答2:

telnet on port 80

For example:

telnet www.your-server.com/pageToTest.aspx 80

then type GET



回答3:

This can be done using wget.



回答4:

I've had some good luck with cURL http://curl.haxx.se/ to replicate sending JSON to a webservice. Perhaps this might help you too.



回答5:

Telnet is really for connecting to a remote telnet server. In fact it (telnet server) is not present in Windows 10, only the client. You better use PowerShell. Here is an example accessing ODATA service: http://hodentekhelp.blogspot.com/2014/11/can-you-access-odata-with-powershell.html

Also review this thread: https://social.technet.microsoft.com/Forums/en-US/035062dd-5052-4abe-bd9a-8714f4184806/there-is-no-telnet-server-in-windows-10-what-is-the-purpose-of-telnet-client?forum=win10itprogeneral



回答6:

Another way is to use wget which is a common command line tool (v useful for downloading). On windows you can get it from here http://gnuwin32.sourceforge.net/packages/wget.htm and its already part of most Linux distros. To use simply do the following;-

wget google.com

and that will return the following

--2018-03-20 16:31:39--  http://google.com/
Resolving google.com... 216.58.204.14
Connecting to google.com|216.58.204.14|:80... connected.
HTTP request sent, awaiting response... 302 Found
Location: http://www.google.co.uk/?gfe_rd=cr&dcr=0&ei=dzexWqybGof38Afo3ZmACg [following]
--2018-03-20 16:31:39--  http://www.google.co.uk/?gfe_rd=cr&dcr=0&ei=dzexWqybGof38Afo3ZmACg
Resolving www.google.co.uk... 216.58.201.3
Connecting to www.google.co.uk|216.58.201.3|:80... connected.
HTTP request sent, awaiting response... 200 OK
Length: unspecified [text/html]
Saving to: `index.html@gfe_rd=cr&dcr=0&ei=dzexWqybGof38Afo3ZmACg'

    [ <=>                                                                                                                                                                                                 ] 12,441      --.-K/s   in 0s

2018-03-20 16:31:40 (88.3 MB/s) - `index.html@gfe_rd=cr&dcr=0&ei=dzexWqybGof38Afo3ZmACg' saved [12441]