麻豆小视频在线观看_中文黄色一级片_久久久成人精品_成片免费观看视频大全_午夜精品久久久久久久99热浪潮_成人一区二区三区四区

首頁 > 開發 > PowerShell > 正文

PowerShell中使用curl(Invoke-WebRequest)的方法教程

2020-03-26 18:52:54
字體:
來源:轉載
供稿:網友

前言

PowerShell能干什么呢?PowerShell首先是個Shell,定義好了一堆命令與操作系統,特別是與文件系統交互,能夠啟動應用程序,甚至操縱應用程序;第二,PowerShell允許將幾個命令組合起來放到文件里執行,實現文件級的重用,也就是說有腳本的性質;第三,PowerShell能夠能夠充分利用.Net類型和COM對象,來簡單地與各種系統交互,完成各種復雜的、自動化的操作。

當我們習慣了windows的界面模式就很難轉去命令行,甚至以命令行發家的git也涌現出各種界面tool。然而命令行真的會比界面快的多,如果你是一個碼農。

situation:接到需求分析bug,需要訪問http。那臺機器屬于product,不允許裝postman。我只能手動命令行來發請求。發現了內置的PowerShell中有curl命令。歡喜試了半天,總是命令不對,google發現這個curl是冒名頂替的,只是一個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簡單用法

1.用途

Gets content from a web page on the Internet.

獲取http web請求訪問內容

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.簡單的幾個用法

3.1 Get請求

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

會發現content內容被截斷了。想要獲取完整的content:

ps> curl https://www.google.com | Select -ExpandProperty Content

3.2添加header

-Headers @{"accept"="application/json"}

3.3指定Method

-Method Get

3.4將獲取到的content輸出到文件

-OutFile 'c:/Users/rmiao/temp/content.txt'

3.5表單提交

For example:$R = Invoke-WebRequest http://website.com/login.aspx $R.Forms[0].Name = "MyName" $R.Forms[0].Password = "MyPassword" Invoke-RestMethod http://website.com/service.aspx -Body $R

or

Invoke-RestMethod http://website.com/service.aspx -Body $R.Forms[0]

3.6內容篩選

PS C:/Users/rmiao> $R = Invoke-WebRequest -URI http://www.bing.com?q=how+many+feet+in+a+milePS C:/Users/rmiao> $R.AllElements | where {$_.innerhtml -like "*=*"} | Sort { $_.InnerHtml.Length } | Select InnerText -First 5innerText---------=1Next=

3.7一個登陸示例

#發送一個登陸請求,聲明一個sessionVariable 參數為fb, 將結果保存在$R#這個變量FB就是header.cookie等集合PS C:/Users/rmiao> $R=curl http://www.facebook.com/login.php -SessionVariable fbPS C:/Users/rmiao> $FBHeaders    : {}Cookies    : System.Net.CookieContainerUseDefaultCredentials : FalseCredentials   :Certificates   :UserAgent    : Mozilla/5.0 (Windows NT; Windows NT 6.3; en-US) WindowsPowerShell/4.0Proxy     :MaximumRedirection : -1#將response響應結果中的第一個form屬性賦值給變量FormPS C:/Users/rmiao> $Form=$R.Forms[0]PS C:/Users/rmiao> $Form.fieldsKey               Value---               -----lsd               AVqQqrLWdisplayenable_profile_selectorisprivatelegacy_return            0profile_selector_idsreturn_sessionskip_api_loginsigned_nexttrynum              1u_0_0u_0_1lgnrnd              214945_qGeglgnjs              nemailpasspersistentdefault_persistent           1# 查看formPS C:/Users/rmiao> $Form | Format-ListId  : login_formMethod : postAction : /login.php?login_attempt=1&lwv=100Fields : {[lsd, AVqQqrLW], [display, ], [enable_profile_selector, ], [isprivate, ]...}#查看屬性$Form.fields#設置賬號密碼$Form.Fields["email"] = "[email protected]"$Form.Fields["pass"] = "P@ssw0rd"#發送請求并保存結果為$R$R=Invoke-WebRequest -Uri ("https://www.facebook.com" + $Form.Action) -WebSession $FB -Method POST -Body $Form.Fields#查看結果PS C:/Users/rmiao> $R.StatusDescriptionOK

雖然沒有curl那么主流,但一樣可以成為http訪問的一個選擇。

總結

以上就是這篇文章的全部內容了,希望本文的內容對大家的學習或者工作能帶來一定的幫助,如果有疑問大家可以留言交流,謝謝大家對VEVB武林網的支持。

參考

https://technet.microsoft.com/en-us/library/hh849901.aspx

 

發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 国内精品伊人久久 | 色播视频在线播放 | 亚洲午夜激情网 | 成人在线视频播放 | 黄色影院一级片 | 久久人人av | 亚洲精品久久久久久 | 91久久精品一 | 欧美成人免费在线视频 | 成年性羞羞视频免费观看无限 | 国产精品久久久久久婷婷天堂 | 曰韩在线视频 | 精品成人国产在线观看男人呻吟 | 久草在线最新 | 国产做爰全免费的视频黑人 | 久久久国产精品网站 | av人人| 成人区一区二区三区 | 亚洲视频在线观看免费视频 | 一级黄色淫片 | 黄色免费电影网址 | 精品久久9999 | 久久凹凸 | 国产色视频免费 | 成人国产精品色哟哟 | 亚洲成人网一区 | 精品亚洲午夜久久久久91 | 成人短视频在线观看免费 | 国产精品久久久在线观看 | 国产一级做a爱片在线看免 2019天天干夜夜操 | 日韩av手机在线免费观看 | 麻豆蜜桃在线观看 | 在线播放免费视频 | 蜜桃免费在线 | xxxxxx视频| 一级电影免费 | 日本黄色一级毛片 | 免费网址黄 | 国产精品久久久久久久久久久久久久久 | 欧美黄色一级片视频 | 91成人在线免费 |