如何从命令行发布http请求

时间:2010-11-25 12:56:21

标签: asp.net http command-line

您好 我需要在dos命令行中向aspx页面发布请求..我该怎么办?

7 个答案:

答案 0 :(得分:19)

端口80上的telnet

例如:

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

然后输入GET

答案 1 :(得分:6)

创建一个包含以下内容的.vbs文件:

' 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

然后执行:

cscript.exe scriptname.vbs

答案 2 :(得分:4)

可以使用wget完成此操作。

答案 3 :(得分:2)

我已经通过cURL http://curl.haxx.se/获得了一些好运,可以将JSON发送到Web服务。也许这对你也有帮助。

答案 4 :(得分:1)

Telnet实际上是用于连接远程telnet服务器。实际上它(telnet服务器)在Windows 10中不存在,只有客户端。 您最好使用PowerShell。以下是访问ODATA服务的示例: http://hodentekhelp.blogspot.com/2014/11/can-you-access-odata-with-powershell.html

同时查看此主题: 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

答案 5 :(得分:1)

所有这些答案都需要安装Windows功能或其他程序。 Powershell是默认安装的,可以从命令行运行

powershell -command "Invoke-WebRequest -Uri %url% -Method POST"

答案 6 :(得分:0)

另一种方法是使用wget,这是一个常用的命令行工具(对下载很有用)。在Windows上,您可以从http://gnuwin32.sourceforge.net/packages/wget.htm获取它,它已经是大多数Linux发行版的一部分。要使用,只需执行以下操作; -

wget google.com

,这将返回以下

--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]