Post asp.net form invoke web-request

  • Jo Pattyn

    SSC-Dedicated

    Points: 31401

     

    The following code works, but now i'm trying to find the usebasicparsing equivalent. The page in question is an asp.net form.

    Are there any code sample to retrieve Forms.Fields with usebasicparsing?

    #WebPageWithForm
    $Uri = "UrlWithForm"
    #GetWebPage
    $result = Invoke-WebRequest $Uri -SessionVariable my_session -TimeoutSec 60 -UseDefaultCredentials
    #Try to change some fields from searchform
    $form = $result.Forms['aspnetForm']
    $form.Fields['ctl00$MainContent$MyTextBox'] = "ABC"
    #Post fields to retrieve the required item
    $mainPage = Invoke-WebRequest $Uri -WebSession $my_session -Body $form.Fields -Method Post -TimeoutSec 60 -UseDefaultCredentials
    #Verify we got a result
    $DatabaseTrueFound=$webpagina | Where {$_.Content -match 'ABC'}
    return $DatabaseTrueFound -ne $null ?
    #WebPageWithForm
    $Uri = "UrlWithForm"
    #GetWebPage with basicparsing
    $result = Invoke-WebRequest $Uri -SessionVariable my_session -TimeoutSec 60 -UseDefaultCredentials -UseBasicParsing
    #Try to change some fields from searchform
    $postParams=@{
    ctl00$MainContent$MyTextBox='ABC'
    }
    $result2 = Invoke-WebRequest -Uri ($Uri) -Method POST -Body $postParams -UseDefaultCredentials -WebSession $my_session -TimeoutSec 60
    #Verify we got a result, Always fails, not all fields passed
    $DatabaseTrueFound=$webpagina | Where {$_.Content -match 'ABC'}
    return $DatabaseTrueFound -ne $null

     

  • Site Owners

    SSC Guru

    Points: 80375

    Thanks for posting your issue and hopefully someone will answer soon.

    This is an automated bump to increase visibility of your question.

Viewing 2 posts - 1 through 2 (of 2 total)

You must be logged in to reply to this topic. Login to reply