Jump to content

"AutoIt" User Agent String


Recommended Posts

From the changelog:

# Changed: AutoIt internet functions (e.g. InetGet()) now use "AutoIt" as a user-agent. Previously using blank

which was blocked by many websites.

Is there a way to set the user-agent to something other than "AutoIt" via an opt?

Lofting the cyberwinds on teknoleather wings, I am...The Blue Drache

Link to comment
Share on other sites

This works. Looks like you can use ADODB.Stream to work with the binary result:

http://www.autoitscript.com/forum/index.ph...hl=responsebody

#cs ----------------------------------------------------------------------------

 AutoIt Version: 3.2.12.0
 Author:         WeaponX / lod3n

 Script Function:
    Download file with header

#ce ----------------------------------------------------------------------------
$oMyError = ObjEvent("AutoIt.Error","MyErrFunc")

$oHTTP = ObjCreate('winhttp.winhttprequest.5.1')
$oHTTP.Open('GET', 'http://www.google.com/intl/en_ALL/images/logo.gif', FALSE)
$oHTTP.SetRequestHeader("User-Agent", "Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1; SV1; .NET CLR 1.1.4322; .NET CLR 2.0.50727; .NET CLR 3.0.04506.30; .NET CLR 3.0.04506.648; InfoPath.1)")
$oHTTP.Send()

ConsoleWrite("+<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<< HEADERS" & @CRLF)
$Headers = $oHTTP.GetAllResponseHeaders() 
ConsoleWrite($Headers & @CRLF)

;ConsoleWrite("+<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<< USER-AGENT" & @CRLF)
;$Agent = $oHTTP.GetResponseHeader("HTTP_USER_AGENT") 
;ConsoleWrite($Agent & @CRLF)

ConsoleWrite("+<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<< Status" & @CRLF)
$Status = $oHTTP.Status
ConsoleWrite($Status & @CRLF)

ConsoleWrite("+<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<< StatusText" & @CRLF)
$StatusText = $oHTTP.StatusText
ConsoleWrite($StatusText & @CRLF)

If $Status = 200 Then
    
    $oBinaryStream = ObjCreate("ADODB.Stream")  
    
    $filename = @DesktopDir & "\test.gif"
    
    $adTypeBinary = 1
    $adSaveCreateOverWrite = 2     
    FileDelete($filename)
    $oBinaryStream.Type = $adTypeBinary
    $oBinaryStream.Open
    $oBinaryStream.Write($oHttp.ResponseBody)
    $oBinaryStream.SaveToFile($filename, $adSaveCreateOverWrite)
EndIf

;--------------------------------
;COM Error Handler
;--------------------------------
Func MyErrFunc()
    Local $HexNumber
    $HexNumber=hex($oMyError.number,8)
    Msgbox(0,"COM Error ","We intercepted a COM Error !" & @CRLF & @CRLF & _
    "err.description is: " & @TAB & $oMyError.description & @CRLF & _
    "err.windescription:" & @TAB & $oMyError.windescription & @CRLF & _
    "err.number is: " & @TAB & $HexNumber & @CRLF & _
    "err.lastdllerror is: " & @TAB & $oMyError.lastdllerror & @CRLF & _
    "err.scriptline is: " & @TAB & $oMyError.scriptline & @CRLF & _
    "err.source is: " & @TAB & $oMyError.source & @CRLF & _
    "err.helpfile is: " & @TAB & $oMyError.helpfile & @CRLF & _
    "err.helpcontext is: " & @TAB & $oMyError.helpcontext _
    )
    SetError(1) ; to check for after this function returns
Endfunc
Edited by weaponx
Link to comment
Share on other sites

Right out of help file InetGet() remarks section.

Zing! You completely MISSED it. Thank you for playing, here's your kwepie consolation prize.

AFAIK no

Hmm. Ok. Thanks.

This works. Looks like you can use ADODB.Stream to work with the binary result:

http://www.autoitscript.com/forum/index.ph...hl=responsebody

<...snip...>

Ouch. Not as simple as I'd hoped. *shrug* Thanks for the effort.

Lofting the cyberwinds on teknoleather wings, I am...The Blue Drache

Link to comment
Share on other sites

@Blue_Drache

You can (and should muttley ) make a feature request on this issue, imho, it's reasonable to have User Agent line as optional parameter (at least for InetGet/Size() functions), i think some pages might require a full user agent (with data such as browser, version, system, etc.).

 

Spoiler

Using OS: Win 7 Professional, Using AutoIt Ver(s): 3.3.6.1 / 3.3.8.1

AutoIt_Rus_Community.png AutoIt Russian Community

My Work...

Spoiler

AutoIt_Icon_small.pngProjects: ATT - Application Translate Tool {new}| BlockIt - Block files & folders {new}| SIP - Selected Image Preview {new}| SISCABMAN - SciTE Abbreviations Manager {new}| AutoIt Path Switcher | AutoIt Menu for Opera! | YouTube Download Center! | Desktop Icons Restorator | Math Tasks | KeyBoard & Mouse Cleaner | CaptureIt - Capture Images Utility | CheckFileSize Program

AutoIt_Icon_small.pngUDFs: OnAutoItErrorRegister - Handle AutoIt critical errors {new}| AutoIt Syntax Highlight {new}| Opera Library! | Winamp Library | GetFolderToMenu | Custom_InputBox()! | _FileRun UDF | _CheckInput() UDF | _GUIInputSetOnlyNumbers() UDF | _FileGetValidName() UDF | _GUICtrlCreateRadioCBox UDF | _GuiCreateGrid() | _PathSplitByRegExp() | _GUICtrlListView_MoveItems - UDF | GUICtrlSetOnHover_UDF! | _ControlTab UDF! | _MouseSetOnEvent() UDF! | _ProcessListEx - UDF | GUICtrl_SetResizing - UDF! | Mod. for _IniString UDFs | _StringStripChars UDF | _ColorIsDarkShade UDF | _ColorConvertValue UDF | _GUICtrlTab_CoverBackground | CUI_App_UDF | _IncludeScripts UDF | _AutoIt3ExecuteCode | _DragList UDF | Mod. for _ListView_Progress | _ListView_SysLink | _GenerateRandomNumbers | _BlockInputEx | _IsPressedEx | OnAutoItExit Handler | _GUICtrlCreateTFLabel UDF | WinControlSetEvent UDF | Mod. for _DirGetSizeEx UDF
 
AutoIt_Icon_small.pngExamples: 
ScreenSaver Demo - Matrix included | Gui Drag Without pause the script | _WinAttach()! | Turn Off/On Monitor | ComboBox Handler Example | Mod. for "Thinking Box" | Cool "About" Box | TasksBar Imitation Demo

Like the Projects/UDFs/Examples? Please rate the topic (up-right corner of the post header: Rating AutoIt_Rating.gif)

* === My topics === *

==================================================
My_Userbar.gif
==================================================

 

 

 

AutoIt is simple, subtle, elegant. © AutoIt Team

Link to comment
Share on other sites

Ouch. Not as simple as I'd hoped. *shrug* Thanks for the effort.

Not really complex either. If you strip out the error checking and debug stuff the function is easy.

InetGetX('http://www.google.com/intl/en_ALL/images/logo.gif', @ScriptDir & "\google.gif")
Func InetGetX($sURL, $sFilename, $sUserAgent = "")
    
    ;If User Agent string is empty, use Firefox 3.0
    If $sUserAgent = "" Then
        $sUserAgent = "Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1; SV1; .NET CLR 1.1.4322; .NET CLR 2.0.50727; .NET CLR 3.0.04506.30; .NET CLR 3.0.04506.648; InfoPath.1)"
    EndIf
    
    $oHTTP = ObjCreate('winhttp.winhttprequest.5.1')
    $oHTTP.Open('GET', $sURL, FALSE)
    $oHTTP.SetRequestHeader("User-Agent", $sUserAgent)
    $oHTTP.Send()

    ;If HTTP Status OK, save file
    If $oHTTP.Status = 200 Then
        $oBinaryStream = ObjCreate("ADODB.Stream")     
        $adTypeBinary = 1
        $adSaveCreateOverWrite = 2     
        FileDelete($sFilename)
        $oBinaryStream.Type = $adTypeBinary
        $oBinaryStream.Open
        $oBinaryStream.Write($oHttp.ResponseBody)
        $oBinaryStream.SaveToFile($sFilename, $adSaveCreateOverWrite)
    EndIf
EndFunc
Link to comment
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
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...