最新国产好看的视频,伊人天堂AV在线,国产Aaaaaa视频,蜜臀视频在线观看一区,人妻av色图,密臀久久久精品影片,青青视频免费观看毛片,久草在线观看视,国产三级精品色情在线

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

 更新時(shí)間:2017年08月04日 11:38:35   作者:Ryan.Miao  
這篇文章主要給大家介紹了關(guān)于在PowerShell中使用curl(Invoke-WebRequest)的方法教程,文中通過(guò)詳細(xì)的示例代碼給大家介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面來(lái)一起看看吧。

前言

PowerShell能干什么呢?PowerShell首先是個(gè)Shell,定義好了一堆命令與操作系統(tǒng),特別是與文件系統(tǒng)交互,能夠啟動(dòng)應(yīng)用程序,甚至操縱應(yīng)用程序;第二,PowerShell允許將幾個(gè)命令組合起來(lái)放到文件里執(zhí)行,實(shí)現(xiàn)文件級(jí)的重用,也就是說(shuō)有腳本的性質(zhì);第三,PowerShell能夠能夠充分利用.Net類型和COM對(duì)象,來(lái)簡(jiǎn)單地與各種系統(tǒng)交互,完成各種復(fù)雜的、自動(dòng)化的操作。

當(dāng)我們習(xí)慣了windows的界面模式就很難轉(zhuǎn)去命令行,甚至以命令行發(fā)家的git也涌現(xiàn)出各種界面tool。然而命令行真的會(huì)比界面快的多,如果你是一個(gè)碼農(nóng)。

situation:接到需求分析bug,需要訪問(wèn)http。那臺(tái)機(jī)器屬于product,不允許裝postman。我只能手動(dòng)命令行來(lái)發(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 -AutoSize

CommandType Name      Version Source
----------- ----      ------- ------
Alias  curl -> Invoke-WebRequest
Alias  iwr -> Invoke-WebRequest
Alias  wget -> Invoke-WebRequest

Invoke-WebRequest簡(jiǎn)單用法

1.用途

Gets content from a web page on the Internet.

獲取http web請(qǐng)求訪問(wèn)內(nèi)容

2.語(yǔ)法Syntax

Parameter Set: Default
Invoke-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.com

StatusCode  : 200
StatusDescription : OK
Content   : <!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

會(huì)發(fā)現(xiàn)content內(nèi)容被截?cái)嗔恕O胍@取完整的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內(nèi)容篩選

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

innerText
---------
=

1
Next
=

3.7一個(gè)登陸示例

#發(fā)送一個(gè)登陸請(qǐng)求,聲明一個(gè)sessionVariable 參數(shù)為fb, 將結(jié)果保存在$R
#這個(gè)變量FB就是header.cookie等集合
PS C:\Users\rmiao> $R=curl http://www.facebook.com/login.php -SessionVariable fb
PS C:\Users\rmiao> $FB


Headers    : {}
Cookies    : System.Net.CookieContainer
UseDefaultCredentials : False
Credentials   :
Certificates   :
UserAgent    : Mozilla/5.0 (Windows NT; Windows NT 6.3; en-US) WindowsPowerShell/4.0
Proxy     :
MaximumRedirection : -1


#將response響應(yīng)結(jié)果中的第一個(gè)form屬性賦值給變量Form
PS C:\Users\rmiao> $Form=$R.Forms[0]
PS C:\Users\rmiao> $Form.fields

Key               Value
---               -----
lsd               AVqQqrLW
display
enable_profile_selector
isprivate
legacy_return            0
profile_selector_ids
return_session
skip_api_login
signed_next
trynum              1
u_0_0
u_0_1
lgnrnd              214945_qGeg
lgnjs              n
email
pass
persistent
default_persistent           1



# 查看form
PS C:\Users\rmiao> $Form | Format-List


Id  : login_form
Method : post
Action : /login.php?login_attempt=1&lwv=100
Fields : {[lsd, AVqQqrLW], [display, ], [enable_profile_selector, ], [isprivate, ]...}


#查看屬性
$Form.fields

#設(shè)置賬號(hào)密碼
$Form.Fields["email"] = "User01@Fabrikam.com"
$Form.Fields["pass"] = "P@ssw0rd"

#發(fā)送請(qǐng)求并保存結(jié)果為$R
$R=Invoke-WebRequest -Uri ("https://www.facebook.com" + $Form.Action) -WebSession $FB -Method POST -Body $Form.Fields

#查看結(jié)果
PS C:\Users\rmiao> $R.StatusDescription
OK

雖然沒(méi)有curl那么主流,但一樣可以成為http訪問(wèn)的一個(gè)選擇。

總結(jié)

以上就是這篇文章的全部?jī)?nèi)容了,希望本文的內(nèi)容對(duì)大家的學(xué)習(xí)或者工作能帶來(lái)一定的幫助,如果有疑問(wèn)大家可以留言交流,謝謝大家對(duì)腳本之家的支持。

參考

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

相關(guān)文章

  • PowerShell創(chuàng)建Byte數(shù)組例子

    PowerShell創(chuàng)建Byte數(shù)組例子

    這篇文章主要介紹了PowerShell創(chuàng)建Byte數(shù)組例子,Byte數(shù)組即字節(jié)數(shù)組,它是一種強(qiáng)類型的數(shù)組,需要的朋友可以參考下
    2014-08-08
  • PowerShell 未經(jīng)數(shù)字簽名 系統(tǒng)將不執(zhí)行該腳本

    PowerShell 未經(jīng)數(shù)字簽名 系統(tǒng)將不執(zhí)行該腳本

    這篇文章主要介紹了PowerShell 未經(jīng)數(shù)字簽名 系統(tǒng)將不執(zhí)行該腳本的相關(guān)資料
    2017-10-10
  • Windows 8 中的 PowerShell 3.0

    Windows 8 中的 PowerShell 3.0

    PowerShell并不是在Windows 8上首次出現(xiàn),所以,很多IT專業(yè)人員、程序員和高級(jí)用戶都非常熟悉了。在這里重提PowerShell,主要是為了為一些之前沒(méi)有了解過(guò)PowerShell用戶,還有對(duì)PowerShell 3.0不是特別了解的用戶。PowerShell高手可以跳過(guò)此文。
    2015-09-09
  • PowerShell中調(diào)用WPF生成炫酷窗口實(shí)例

    PowerShell中調(diào)用WPF生成炫酷窗口實(shí)例

    這篇文章主要介紹了PowerShell中調(diào)用WPF生成炫酷窗口實(shí)例,本文直接給出運(yùn)行效果和腳本源碼,需要的朋友可以參考下
    2015-03-03
  • PowerShell小技巧之嘗試ssh登錄

    PowerShell小技巧之嘗試ssh登錄

    由于Linux登錄大多是通過(guò)SSH的模式進(jìn)行登錄的,滲透測(cè)試時(shí)掃描到22端口監(jiān)聽(tīng)有SSH,如果能有腳本可以基于字典對(duì)Linux進(jìn)行用戶名和密碼的嘗試,將會(huì)在滲透測(cè)試時(shí)起到很重要的作用。本文中將會(huì)向大家介紹如何通過(guò)PowerShell嘗試Linux SSH登錄。
    2014-10-10
  • PowerShell小技巧之同時(shí)使用可選強(qiáng)制參數(shù)

    PowerShell小技巧之同時(shí)使用可選強(qiáng)制參數(shù)

    本文主要講訴了在腳本函數(shù)中讓可選參數(shù)和強(qiáng)制參數(shù)必須同時(shí)使用,有需要的朋友可以參考下。
    2014-09-09
  • PowerShell: Try...Catch...Finally 實(shí)現(xiàn)方法

    PowerShell: Try...Catch...Finally 實(shí)現(xiàn)方法

    PowerShell 本身有很多很好的錯(cuò)誤控制,但是習(xí)慣于.net編程的人員,更喜歡用Try Catch Finally方法,尤其當(dāng)有一段代碼必須被執(zhí)行到的時(shí)候。現(xiàn)在好了,adweigert 想出了一個(gè)好方法來(lái)實(shí)現(xiàn)。這個(gè)函數(shù)已經(jīng)在多種情況下測(cè)試過(guò),希望能對(duì)你有幫助
    2013-11-11
  • 探索PowerShell (四) PowerShell的對(duì)象、格式與參數(shù)

    探索PowerShell (四) PowerShell的對(duì)象、格式與參數(shù)

    本節(jié)將要給大家介紹一下PowerShell下的對(duì)象,基本格式以及參數(shù)。依然屬于PowerShell的基礎(chǔ)
    2012-12-12
  • PowerShell中Job相關(guān)命令及并行執(zhí)行任務(wù)詳解

    PowerShell中Job相關(guān)命令及并行執(zhí)行任務(wù)詳解

    這篇文章主要給大家介紹了關(guān)于PowerShell中Job相關(guān)命令及并行執(zhí)行任務(wù)的相關(guān)資料,文中通過(guò)示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面隨著小編來(lái)一起學(xué)習(xí)學(xué)習(xí)吧。
    2018-03-03
  • PowerShell函數(shù)中使用$PSBoundParameters獲取輸入?yún)?shù)列表實(shí)例

    PowerShell函數(shù)中使用$PSBoundParameters獲取輸入?yún)?shù)列表實(shí)例

    這篇文章主要介紹了PowerShell函數(shù)中使用$PSBoundParameters獲取輸入?yún)?shù)列表實(shí)例,需要的朋友可以參考下
    2014-07-07

最新評(píng)論

分宜县| 鄂伦春自治旗| 清涧县| 石渠县| 赞皇县| 库伦旗| 浦江县| 连江县| 大城县| 青铜峡市| 房产| 横山县| 监利县| 惠东县| 平陆县| 根河市| 岳普湖县| 横山县| 华阴市| 金寨县| 兖州市| 三门峡市| 屏边| 枣强县| 海口市| 迁西县| 玉山县| 彰武县| 昭苏县| 佳木斯市| 宜章县| 元谋县| 镇江市| 东光县| 当阳市| 昌宁县| 榆社县| 枞阳县| 武鸣县| 大同市| 宿迁市|