代码之家  ›  专栏  ›  技术社区  ›  TonyP

如何从命令行发布http请求

  •  7
  • TonyP  · 技术社区  · 15 年前

    您好! 我需要在dos命令行中向aspx页面发送请求。。我该怎么做?

    6 回复  |  直到 15 年前
        1
  •  6
  •   LikeableBias    12 年前

    创建包含以下内容的.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
  •  19
  •   m.edmondson    15 年前

    端口80上的telnet

    例如:

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

    然后键入 GET

        3
  •  4
  •   Dirk Vollmar    15 年前

    这可以用 wget .

        4
  •  2
  •   Tom    15 年前

    我在卷发方面运气不错 http://curl.haxx.se/ 复制将JSON发送到web服务。也许这对你也有帮助。

        5
  •  1
  •   user2063329    10 年前

    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

        6
  •  0
  •   momomo    8 年前

    另一种方法是使用wget,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]