前言
PowerShell能干什么呢?PowerShell首先是個(gè)Shell,定義好了一堆命令與操作系統(tǒng),特別是與文件系統(tǒng)交互,能夠啟動(dòng)應(yīng)用程序,甚至操縱應(yīng)用程序;第二,PowerShell允許將幾個(gè)命令組合起來放到文件里執(zhí)行,實(shí)現(xiàn)文件級(jí)的重用,也就是說有腳本的性質(zhì);第三,PowerShell能夠能夠充分利用.Net類型和COM對(duì)象,來簡(jiǎn)單地與各種系統(tǒng)交互,完成各種復(fù)雜的、自動(dòng)化的操作。
當(dāng)我們習(xí)慣了windows的界面模式就很難轉(zhuǎn)去命令行,甚至以命令行發(fā)家的git也涌現(xiàn)出各種界面tool。然而命令行真的會(huì)比界面快的多,如果你是一個(gè)碼農(nóng)。
situation:接到需求分析bug,需要訪問http。那臺(tái)機(jī)器屬于product,不允許裝postman。我只能手動(dòng)命令行來發(fā)請(qǐng)求。發(fā)現(xiàn)了內(nèi)置的PowerShell中有curl命令。歡喜試了半天,總是命令不對(duì),google發(fā)現(xiàn)這個(gè)curl是冒名頂替的,只是一個(gè)Invoke-WebRequest的alias。參考。
PS> Get-Alias -Definition Invoke-WebRequest | Format-Table -AutoSizeCommandType Name Version Source----------- ---- ------- ------Alias curl -> Invoke-WebRequestAlias iwr -> Invoke-WebRequestAlias wget -> Invoke-WebRequest
Invoke-WebRequest簡(jiǎn)單用法
1.用途
Gets content from a web page on the Internet.
獲取http web請(qǐng)求訪問內(nèi)容
2.語法Syntax
Parameter Set: DefaultInvoke-WebRequest [-Uri] <Uri> [-Body <Object> ] [-Certificate <X509Certificate> ] [-CertificateThumbprint <String> ] [-ContentType <String> ] [-Credential <PSCredential> ] [-DisableKeepAlive] [-Headers <IDictionary> ] [-InFile <String> ] [-MaximumRedirection <Int32> ] [-Method <WebRequestMethod> {Default | Get | Head | Post | Put | Delete | Trace | Options | Merge | Patch} ] [-OutFile <String> ] [-PassThru] [-Proxy <Uri> ] [-ProxyCredential <PSCredential> ] [-ProxyUseDefaultCredentials] [-SessionVariable <String> ] [-TimeoutSec <Int32> ] [-TransferEncoding <String> {chunked | compress | deflate | gzip | identity} ] [-UseBasicParsing] [-UseDefaultCredentials] [-UserAgent <String> ] [-WebSession <WebRequestSession> ] [ <CommonParameters>]
3.簡(jiǎn)單的幾個(gè)用法
3.1 Get請(qǐng)求
PS C:/Users/rmiao> curl -URi https://www.google.comStatusCode : 200StatusDescription : OKContent : <!doctype html><html itemscope="" itemtype="http://schema.org/WebPage" lang="en"><head><meta content="Search the world's information, including webpages, images, videos and more. Google has many speci..."RawContent : HTTP/1.1 200 OK X-XSS-Protection: 1; mode=block X-Frame-Options: SAMEORIGIN Alt-Svc: quic=":443"; ma=2592000; v="36,35,34,33,32" Vary: Accept-Encoding Transfer-Encoding: chunked
新聞熱點(diǎn)
疑難解答
圖片精選