What is Forms[0] for Invoke-WebRequest results on PowerShell?

Asked 1 years ago, Updated 1 years ago, 472 views

There are some parts of the code listed on the following site that I don't understand.
Why are you substituting Forms[0] for $response?What does it mean?

Form posts with PowerShell

$form=$response.Forms[0]

Also, the code below is an error.Why?

$response="aaa"
$form=$response.Form[0]

powershell

2022-12-31 14:06

2 Answers

The previous code is important.

$response=Invoke-WebRequest-Uri$myUrl-Method GET-SessionVariable mySession

$form=$response.Forms[0]

and so on.Now it's important to know what Invoke-WebRequest is the cmdlet that outputs.The Notes section of the document contains

PowerShell 6.0.0 Invoke-WebRequest and later support only basic analysis.

As stated, behavior differs between 6.0 and later and less than 6.0.With that in mind, if you look at the output , you can see

BasicHtmlWebResponseObject

and See 5.1 output for

HtmlWebResponseObject

As stated in the note, you can see that there is a specification change in the output.As you can see by looking at each link, the HtmlWebResponseObject output from 5.1 has the Forms property, but BasicHtmlWebRespon outputting 7.2It does not exist in seObject.

The documentation you referred to is probably intended for PowerShell 5.1.In fact, the post date is June 27, 2016, but PowerShell Core 6.0.0 will be released on June 1, 2018.


2022-12-31 16:39

Maybe it's because it's $response as a way to save $myUrl sessions and post forms.

I'm not sure if I can, but I'll give you a SessionValue and replace aaa with username.


2022-12-31 16:57

If you have any answers or tips


© 2024 OneMinuteCode. All rights reserved.