Jump to content
Sign in to follow this  
Synthesis

HTTP Request Problem

Recommended Posts

Synthesis

This is my code

#include <GUIConstantsEx.au3>
#include "WinHTTP.au3"
#include <INet.au3>

Opt('MustDeclareVars', 1)

_Main()

Func _Main()
    Local $filemenu,  $separator1, $web
    Local $exititem, $aboutitem, $okbutton, $header, $link1, $way1, $ss, $ss1
    Local $msg, $file, $link, $way, $hw_open, $hw_connect, $h_openrequest
    #forceref $separator1

    GUICreate("HTTP Request", 300, 150)

    $filemenu = GUICtrlCreateMenu("File")
    $aboutitem = GUICtrlCreateMenuItem("About", $filemenu)
    $separator1 = GUICtrlCreateMenuItem("", $filemenu)
    $exititem = GUICtrlCreateMenuItem("Exit", $filemenu)
    guictrlcreatelabel ("Domain",10,10,50,20)
    $link1 = guictrlcreateinput ("Your domain here (eg : rstcenter.com)", 70,10,200,20)
    guictrlcreatelabel ("Path",10,40,50,20)
    $way1 = guictrlcreateinput ("Path to page (eg : forum/doomclip.rst)",70, 40,200,20)
    $okbutton = GUICtrlCreateButton("Header", 50, 90, 70, 20)
    $ss = guictrlcreatebutton ("Source",180,90,70,20)

    GUISetState()

    While 1
        $msg = GUIGetMsg()


        Select
            Case $msg = $GUI_EVENT_CLOSE 
                ExitLoop

            Case $msg = $exititem
                ExitLoop
                
            case $msg = $ss
                    $way = guictrlread ($way1)
                    $link = guictrlread ($link1)
                    $web = $link & "/" & $way
                    $ss1 = _INetGetSource ($web)
                    clipput ($ss1)
                    msgbox (64,"Http Request", "The full source has been copied to clipboard." & @crlf & "Open a text editor and press CTRL+V to paste the code")
                    

            Case $msg = $okbutton
                    $way = guictrlread ($way1)
                    $link = guictrlread ($link1)
                
                    $hw_open = _WinHttpOpen()

                    $hw_connect = _WinHttpConnect($hw_open, $link)

                    $h_openRequest = _WinHttpOpenRequest($hw_connect, "GET", $way)

                    _WinHttpSendRequest($h_openRequest)

                    _WinHttpReceiveResponse($h_openRequest)

                    If _WinHttpQueryDataAvailable($h_openRequest) Then 
                    $header = _WinHttpQueryHeaders($h_openRequest)
                    msgbox (64,"Header",$header)
                    EndIf

                    _WinHttpCloseHandle($h_openRequest)

                    _WinHttpCloseHandle($hw_connect)

                    _WinHttpCloseHandle($hw_open)

            Case $msg = $aboutitem
                MsgBox(0, "About", "Http Request by doomclip")
        EndSelect
    WEnd

    GUIDelete()

    Exit
EndFunc

As you saw, I have 2 inputs. Can someone make them in 1 input please?

Share this post


Link to post
Share on other sites
Authenticity

To make it a single input you need to decide whether the URL request will be something with a page part like:

http://www.google.com/search?q=AutoIt

or anything is allowed, for example:

www.google.com
1.2.3.4.5
this is not a url path at all
etc..

Take a loop for example on this:

Dim $aURL[10] = ["http://www.google.com/search?q=hello", _
                "yahoo.com/join?q=now&b=never", _
                "gov.principle.com/outlaw?name=all", _
                "http://www.www.w ww/loop/www?ww=w", _
                "https://12.145.67.55/", _
                "www.autoitscript.com", _
                "https://www.w3c.com", _
                "221.90.176.5/", _
                "Not URL string", _
                "Nither"]

Dim $sPatt = "^((?:(?:https?|ftp|file)://)?[\w\d]+(?:\.[\w\d]+)+)/(.+)"
UBound()
For $i = 0 To 9
    $aMatch = StringRegExp($aURL[$i], $sPatt, 1)
    If IsArray($aMatch) Then
        ConsoleWrite($i & '-> Host: ' & $aMatch[0] & ', Page: ' & $aMatch[1] & @CRLF)
    EndIf
Next

If you'll change the last part of the regular expression pattern to (?:(.+))? you allow to strings without the page part to return as positive.

Edited by Authenticity

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
Sign in to follow this  

×