簡體   English   中英

如何從命令行發布 http 請求

[英]how to post a http request from command line

您好,我需要在 dos 命令行中向 aspx 頁面發送請求。我該怎么做?

telnet 80 端口

例如:

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

然后輸入GET

創建一個 .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

這可以使用wget來完成。

我在使用 cURL http://curl.haxx.se/復制發送 JSON 到網絡服務方面取得了一些好運。 或許這也能幫到你。

所有這些答案都需要安裝 Windows 功能或其他程序。 Powershell 默認安裝,可以從命令行運行

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

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

這適用於 Windows 10

powershell -command "Invoke-WebRequest -UseBasicParsing -Method POST -Uri http://example.com/login -Body username=exampleuser'&'password=test"

更多信息在這里https://learn.microsoft.com/en-us/powershell/module/microsoft.powershell.utility/invoke-webrequest?view=powershell-7.2

另一種方法是使用 wget,這是一個常用的命令行工具(v 對下載很有用)。 在 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]

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM