Welcome guest. Before posting on our computer help forum, you must register. Click here it's easy and free.

Author Topic: How to send a HTTP request within a batch file?  (Read 19857 times)

0 Members and 1 Guest are viewing this topic.

FoolFish

    Topic Starter


    Newbie

    • Experience: Beginner
    • OS: Unknown
    How to send a HTTP request within a batch file?
    « on: March 27, 2012, 09:36:59 AM »
    Any help would be much appreciated!
    - On SERVER 1, I have a batch file to build a HTTP request, like: http://SERVER2ADDRESS:PORT/SessionControl/CCXML10.start?tokenid=MYCCXMLAPP
    - Within the batch file, what command to use to acutally send the HTTP request such that it will be opened on SERVER 2?

    Geek-9pm


      Mastermind
    • Geek After Dark
    • Thanked: 1026
      • Gekk9pm bnlog
    • Certifications: List
    • Computer: Specs
    • Experience: Expert
    • OS: Windows 10
    Re: How to send a HTTP request within a batch file?
    « Reply #1 on: March 27, 2012, 03:27:42 PM »
    Can a browser make the request?
    Run Internet Explorer From Command Prompt

    Rob Pomeroy



      Prodigy

    • Systems Architect
    • Thanked: 124
      • Me
    • Experience: Expert
    • OS: Other
    Re: How to send a HTTP request within a batch file?
    « Reply #2 on: March 28, 2012, 06:54:43 AM »
    Can you use Powershell?  It can do reasonably sophisticated web transactions.
    Only able to visit the forums sporadically, sorry.

    Geek & Dummy - honest news, reviews and howtos

    Geek-9pm


      Mastermind
    • Geek After Dark
    • Thanked: 1026
      • Gekk9pm bnlog
    • Certifications: List
    • Computer: Specs
    • Experience: Expert
    • OS: Windows 10
    Re: How to send a HTTP request within a batch file?
    « Reply #3 on: March 28, 2012, 10:22:13 AM »
    Rob Pomero, good idea. Here is one on many such tips for PowerShel.

    Quote
    Get-Web (Another round of wget for PowerShell)
    By Joel 'Jaykul' Bennett on 01-May-2008

    Well, after multiple attempts at a wget PowerShell script (the last one works very well for downloading web pages, files, as long as you don’t need to send post parameters or anything like that) ... I found myself writing a script last week that included a custom HTTP POST function as well as using some prior functionality I wrote (ConvertFrom-Html) to convert HTML files to XML documents — which PowerShell can deal with nicely.

    Geek-9pm


      Mastermind
    • Geek After Dark
    • Thanked: 1026
      • Gekk9pm bnlog
    • Certifications: List
    • Computer: Specs
    • Experience: Expert
    • OS: Windows 10

    Rob Pomeroy



      Prodigy

    • Systems Architect
    • Thanked: 124
      • Me
    • Experience: Expert
    • OS: Other
    Re: How to send a HTTP request within a batch file?
    « Reply #5 on: March 29, 2012, 01:48:23 AM »
    Some sample code:

    Code: [Select]
    # WebClient object, for querying a web server through a proxy server with POST data
    $wc = new-Object System.Net.WebClient
    $proxy = New-Object System.Net.WebProxy('proxy.local', '8080')
    $proxy.BypassList = 'someserver.local'
    $wc.proxy = $proxy
    $post_vars = new-object System.Collections.Specialized.NameValueCollection

    # Download a page
    $startpage = $wc.DownloadString("http://wherever.com")

    $post_vars.Add('variable1','value1')
    $post_vars.Add('variable2',$value2)
    $endpage = $wc.UploadValues('http://wherever.com/upload', 'POST', $post_vars)

    # For debugging:
    $response = [System.Text.Encoding]::ASCII.GetString($endpage)
    Write-Host $response
    Only able to visit the forums sporadically, sorry.

    Geek & Dummy - honest news, reviews and howtos