RyukShini

retry request with new proxy WINHTTP

6 posts in this topic

#include "WinHttp.au3"
#include <array.au3>
#include <file.au3>
#include <WinAPI.au3>
#include <string.au3>
#include <WindowsConstants.au3>
#include <FileConstants.au3>
#include <ListviewConstants.au3>
#include <GUIConstantsEx.au3>
#include <MsgBoxConstants.au3>

; Learning HTTP Requests with WinHTTP ;

Global $idOP, $usr, $list, $idEXIT, $call
HotKeySet("{ESC}", "Terminate")

Local $hGUI = GUICreate("Learning", 750, 500, 223, 202, $WS_BORDER)
Local $idEXIT = GUICtrlCreateButton("Exit", 660, 440, 75, Default)
Local $idCon = GUICtrlCreateButton("Start", 10, 10, 725, Default)
Local $siteLab = GUICtrlCreateLabel("Select Test", 20, 48 ,Default, 35)
GUICtrlSetFont (-1,9, 800); bold
Local $IG = GUICtrlCreateCheckbox("test", 75, 45)
Local $realm = GUICtrlCreateCheckbox("test1", 75, 65)
Local $site3 = GUICtrlCreateCheckbox("test2", 200, 45)
Local $site4 = GUICtrlCreateCheckbox("test3", 200, 65)

$list = GUICtrlCreateListView( "     PROXY     |     NAME1     |     NAME2     |     STATUS     ", 20, 100, 710, 300, $LVS_NOSORTHEADER+$LVS_SINGLESEL)


GUISetState(@SW_SHOW, $hGUI)

While 1

        Switch GUIGetMsg()
            Case $GUI_EVENT_CLOSE, $idEXIT
                Exit
            Case $IG
                If _IsChecked($IG) Then
                    $call = "test"
                EndIf
            Case $idCon
                Call($call)

                    EndSwitch
    WEnd

Func test()

$url = "www.w3schools.com"
$sPage = "/tags/demo_form.asp"
Local $proxies
Local $names
_FileReadToArray("proxies.txt", $proxies) ; read the list of names to array
_FileReadToArray("Okay.txt", $names) ; read the list of names to array
For $i = 1 To UBound($proxies) - 1
$Read = $names[$i]
$Datastring = ('')
$newreadamount = _StringBetween($read,$Datastring, ':')
$newreadamount[0] = StringReplace($newreadamount[0], ":", "")
$name1 = $newreadamount[0]
$Datastring2 = (':')
$newreadamount2 = _StringBetween($read,$Datastring2, '')
$newreadamount2[0] = StringReplace($newreadamount2[0], ":", "")
$name2 = $newreadamount2[0]

$sAdditionalData = "name1="&$name1&"&name2="&$name2

        MsgBox(4096, "Test", $proxies[$i] & " - " & $name1&":"&$name2,1)

; Initialize and get session handle

$hOpen = _WinHttpOpen("Mozilla/5.0 (Windows NT 6.1; WOW64; rv:40.0) Gecko/20100101 Firefox/40.0", $WINHTTP_ACCESS_TYPE_NAMED_PROXY, $proxies[$i])
_WinHttpSetTimeouts($hOpen, 15, 15, 15, 15)
; Get connection handle

$hConnect = _WinHttpConnect($hOpen, $url)

; Make a request
$hRequest = _WinHttpOpenRequest($hConnect, "POST", $sPage)

; Send it. Specify additional data to send too. This is required by the Google API:
_WinHttpSendRequest($hRequest, "Content-Type: application/x-www-form-urlencoded", $sAdditionalData)

; Wait for the response
_WinHttpReceiveResponse($hRequest)

; See what's returned
Dim $sReturned
If _WinHttpQueryDataAvailable($hRequest) Then ; if there is data
    Do
        $sReturned &= _WinHttpReadData($hRequest)
    Until @error
EndIf
; Close handles
_WinHttpCloseHandle($hRequest)
_WinHttpCloseHandle($hConnect)
_WinHttpCloseHandle($hOpen)
; See what's returned
MsgBox(4096, "Returned", $sReturned, 1)

If StringInStr($sReturned,'Input was received as:') Then
    GUICtrlCreateListViewItem($proxies[$i] & "|"&$name1&"|"&$name2&"|Success", $list)
    Sleep(500)
    ContinueLoop
ElseIf $sReturned = "" Then
    FileWrite("nottested.txt",$name1&":"&$name2 & @CRLF)
    GUICtrlCreateListViewItem($proxies[$i] & "|"&$name1&"|"&$name2&"|Bad Proxy", $list)
Sleep(500)
ContinueLoop
EndIf

Next

EndFunc

Func Terminate()
    Exit 0
EndFunc

Func _IsChecked($idControlID)
    Return BitAND(GUICtrlRead($idControlID), $GUI_CHECKED) = $GUI_CHECKED
EndFunc   ;==>_IsChecked

This is my code and it runs just fine.
My problem is that if I receive Bad Proxy I need it to test the request again with the same array input $name1 / $name2 until I receive
'Input was received as:'
So basically
 

ElseIf $sReturned = "" Then
    FileWrite("nottested.txt",$name1&":"&$name2 & @CRLF)
    GUICtrlCreateListViewItem($proxies[$i] & "|"&$name1&"|"&$name2&"|Bad Proxy", $list)
Sleep(500)
TRY AGAIN WITH NEW PROXY AND SAME CREDENTIALS
EndIf

Is this possible and if so do you have either some example code and/or some helpfile I can read.

Thanks in advance!

Share this post


Link to post
Share on other sites



Anyone able to help me out??

Thanks in advance.

Share this post


Link to post
Share on other sites

Still trying to figure this out, any help is appreciated.

Share this post


Link to post
Share on other sites

Hello. Just create a function where you can check a return value.

 

so you can  do: Do until (my condition is OK)

 

Saludos

Share this post


Link to post
Share on other sites
On 28/10/2016 at 3:52 PM, Danyfirex said:

Hello. Just create a function where you can check a return value.

 

so you can  do: Do until (my condition is OK)

 

Saludos

I don't really see how that will help in my case?
Sorry.

Share this post


Link to post
Share on other sites

Anyone able to give me an example?
 

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

  • Similar Content

    • CT83
      Need help Website Navigating with HTTPRequests and WinHttp
      By CT83
      (Sorry if this topic is in the wrong section, please suggest a better place if so.)
      Hi! a newbie here, since a few weeks i have got the basic hang of Pixelsearch, Controlclick, Imagesearch functions and now would like to proceed to Automating Internet navigation.
      In this case i am trying to develop a Script which will keep a watch on amazon page and notify me when the price of a commodity drops. I can program the latter part but i still am in search of a better way to , navigate and basically watch webpages with out actually having them on the screen
      Therefore, I need some guidance with HttpRequest, and Winhttp functions, can anyone please refer me to tutorials, links and example scripts for a complete noobbie? Some detailed Video Tutorials, and Guides would just be icing on the cake.
      Sorry, if this sounds too naive. Hoping for positive replies
       
       
    • ntprohd
      how to login to google with winhttp in AutoIt
      By ntprohd
      how to login to google with winhttp in AutoIt
    • jandings
      WinHTTP Get (to a REST API): Authentication problem
      By jandings
      Hello there,
      I'm trying to query a REST API of a webservice, SHOPWARE to be precise. The API is very well documented (https://developers.shopware.com/developers-guide/rest-api/#using-the-rest-api-in-your-own-a) but only using PHP. I tried some stuff but could not make it work.
      It should be very simple, because the following simply works in a Chrome-Browser:
      https://USERNAME:PASSPHRASE@www.SHOPWAREDOMAIN.com/api/orders/300
      queries me for username and passphrase and then dumps order number 300.
      Now I try to do the same in AutoIt (based on the wonderful work of many contributors here):
      #include-once #include "..\INCLUDE\winhttp.au3" #include "..\INCLUDE\OO_JSON.au3" ;Proxy Config Global $oJSON = _OO_JSON_Init() Global $obj = "" Global $sUserName = "USERNAME" Global $sPassword = "PASSPHRASE" Global $sDomain = "www.SHOPWAREDOMAIN.com/api/orders/300" Global $hOpen = _WinHttpOpen("Mozilla/5.0 (Windows NT 6.1; WOW64; rv:40.0) JOC/0.1") ; without ie proxy settings $hConnect = _WinHttpConnect($hOpen, "https://" & $sDomain) ConsoleWrite ($hConnect & "#") $sReturned = _WinHttpSimpleSSLRequest($hConnect, "GET", $sUserName & ":" & $sPassword & "@" & $sDomain, Default ) ;$sReturned = _WinHttpSimpleSSLRequest($hConnect, "GET", $sDomain, Default, $sUserName & ":" & $sPassword) ;$sReturned = _WinHttpSimpleSSLRequest($hConnect, "GET", $sDomain, Default, , $sUserName & ":" & $sPassword ) _WinHttpCloseHandle($hConnect) _WinHttpCloseHandle($hOpen) ; See what's returned ConsoleWrite ($sReturned & "#" & @error) Whatever version I use (I tried the commented ones and many others), I always get a reply from Shopware:
      {"success":false,"message":"Invalid or missing auth"}
      At least this comes from Shopware. But there must be some format of the credentials that I don't know or understand.
      Any help?
    • AutID
      WinHTTPSimpleRequest keep connection alive
      By AutID
      sry my fault. Got this working. It was just a typo mistake. Please delete thread
    • ruslanas402
      WinHTTP & post multi FB image
      By ruslanas402
      Hello there, could anyone advanced in WinHTTP tell me what am I missing please?
      #include "WinHttp.au3" #include <Array.au3> $sPic = "C:\Users\Source\Pictures\Capturex1.PNG" $sPic2 = "C:\Users\Source\Pictures\Capturex2.PNG" $hOpen = _WinHttpOpen() $hConnect = _WinHttpConnect($hOpen, "https://m.facebook.com/") $sRead = _WinHttpSimpleFormFill($hConnect, "login.php", "login_form", "name:email", "login@mail.com", "name:pass", "pasword") $aRead = _WinHttpSimpleFormFill($hConnect, "/groups/1111111111111", "index:1", "name:view_photo", True, "[RETURN_ARRAY]") ;<-- 11111... <-- Group ID $aURL = _WinHttpCrackUrl($aRead[2]) $aRead = _WinHttpSimpleFormFill($hConnect, $aURL[6] & $aURL[7], Default, "name:file1", $sPic, "[RETURN_ARRAY]") $aURL = _WinHttpCrackUrl($aRead[2]) $aRead = _WinHttpSimpleFormFill($hConnect, $aURL[6] & $aURL[7], "index:0", "name:view_photo", True, "[RETURN_ARRAY]") ;<-- Suppose to press on Add More photos isn't? $aURL = _WinHttpCrackUrl($aRead[2]) $aRead = _WinHttpSimpleFormFill($hConnect, $aURL[6] & $aURL[7], Default, "name:file1", $sPic2, "[RETURN_ARRAY]") ; <-- also submit second photo? $aURL = _WinHttpCrackUrl($aRead[2]) _WinHttpSimpleFormFill($hConnect, $aURL[6] & $aURL[7], Default, "name:view_post", True) _WinHttpCloseHandle($hConnect) _WinHttpCloseHandle($hOpen) I'm trying to post multi photos in group, but no luck. Here is idea I came from: