jui*_*0xk 5 windows powershell cmd http wget
当我发出命令时powershell.exe wget http://IP_ADDR:8080/config/version/我得到响应:
StatusCode : 200\nStatusDescription : OK\nContent : {"Content of the web page does not fully show through this output\xe2\x80\xa6 How can I use wget to just show the full content of the webpage without cutting it out?\nRawContent : HTTP/1.1 200 OK\n Content-Length: 307\n Content-Type: application/json\n Date: Wed, 26 Apr 2017 04:20:04 GMT\n Server: CherryPy/3.2.2\n\n {"Content of the web page does not fully show...\nForms : {}\nHeaders : {[Content-Length, 307], [Content-Type, application/json], [Date, Wed, 26 Apr 2017 04:20:04 GMT],\n [Server, CherryPy/3.2.2]}\nImages : {}\nInputFields : {}\nLinks : {}\nParsedHtml : mshtml.HTMLDocumentClass\nRawContentLength : 307\nRun Code Online (Sandbox Code Playgroud)\n\n如上,该命令仅显示部分内容,而不是我正常访问该地址时返回的完整输出。
\n\n我的另一个选择是仅使用 curL,但我想要除第三方工具之外的上述内容的本机解决方案。
\n\n我的问题是,如何使用 wget 命令仅显示内容的输出及其完整输出?
\n根据注释,您需要访问 或.Content属性.RawContent(RawContent 包含 HTTP 标头字段,而 Content 则不包含。请注意,标头也可在属性中使用.Headers):
powershell.exe (wget http://IP_ADDR:8080/config/version/).Content
Run Code Online (Sandbox Code Playgroud)
或者
powershell.exe (wget http://IP_ADDR:8080/config/version/).RawContent
Run Code Online (Sandbox Code Playgroud)
为了解释发生的情况,PowerShell 返回对象而不是纯文本,简单地说它们就像带有可以返回/过滤的属性的迷你数据库等。您在进行调用时看到的是属性子集的默认视图对象的属性,这不是所有可用的属性。
要了解有关 wget 的更多信息,请查找Invoke-WebRequest完整的 cmdlet 名称(wget是它的别名)。
更进一步说,如果您的 Web 调用返回 JSON 或 XML,您可能需要考虑使用它,Invoke-RestMethod因为它将获取 JSON 或 XML 并自动将其转换为 PowerShell 对象(然后您可以在 PowerShell 中进一步操作该对象)。