Jump to content

Recommended Posts

Posted (edited)

Hey guys does anyone know where i can find the udf for inetget... functions.

Tried the include folder with Inet but it was not inside.

I made an alternative function for inetget and i want to check the original one

Edited by ileandros

I feel nothing.It feels great.

  • Moderators
Posted

ileandros,

InetGet is a native AutoIt function, not a UDF, and so is coded in C++ within the closed AutoIt source. :)

M23

Public_Domain.png.2d871819fcb9957cf44f4514551a2935.png Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind

Open spoiler to see my UDFs:

  Reveal hidden contents

 

Posted (edited)

Also did you try the help file.

Edit: Dark blue = native, light blue = UDF

InetGet
_PathSplit
Edited by guinness

UDF List:

  Reveal hidden contents

Updated: 22/04/2018

Posted

Ok cool.

What I'm trying to do is to get the type of the item(.exe , .txt etc) inetget is downloading but I want to do this before start downloading.

Any ideas?

I feel nothing.It feels great.

Posted

Did you search?

UDF List:

  Reveal hidden contents

Updated: 22/04/2018

Posted (edited)

In either case I'm feeling generous.

#include <Constants.au3>

TCPStartup()
MsgBox($MB_SYSTEMMODAL, '', InetGetHeader('http://mirrors.kernel.org/gentoo/releases/amd64/10.1/livedvd-amd64-multilib-10.1.iso') & @CRLF)
TCPShutdown()

Func InetGetHeader($sURL)
    Local Const $aOSArch[2] = ['32', '64']
    Local Const $sUserAgent = 'AutoIt/' & @AutoItVersion & ' (Windows NT ' & _
            RegRead('HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows NT\CurrentVersion\', 'CurrentVersion') & _
            '; Win' & $aOSArch[@AutoItX64] & '; x' & $aOSArch[@AutoItX64] & ' & ) Version/' & @AutoItVersion
    Local Const $sHost = StringRegExpReplace($sURL, '.*://(.*?)/.*', '\1')
    Local Const $sPage = StringRegExpReplace($sURL, '.*://.*?(/.*)', '\1')
    Local Const $sSend = 'HEAD ' & $sPage & ' HTTP/1.1' & @CRLF & _ ; HEAD / GET / POST
            'Host: ' & $sHost & @CRLF & _
            'User-Agent: ' & $sUserAgent & @CRLF & _
            'Referer: ' & $sHost & @CRLF & _
            'Connection: close ' & @CRLF & @CRLF
    Local $sReturn = ''

    Local Const $sIPAddress = TCPNameToIP($sHost)
    If $sIPAddress == '' Then
        Return SetError(@error, 0, $sReturn)
    EndIf

    Local $iSocket = TCPConnect($sIPAddress, 80)
    If Not $iSocket Then
        Return SetError(@error, 0, $sReturn)
    EndIf
    If TCPSend($iSocket, $sSend) = 0 Then
        TCPCloseSocket($iSocket)
        Return SetError(@error, 0, $sReturn)
    EndIf

    Local Const $TCP_MAXLEN = 4096
    Do
        $sReturn &= TCPRecv($iSocket, $TCP_MAXLEN)
    Until @error
    TCPCloseSocket($iSocket)

    Return SetError($sReturn == '', 0, $sReturn)
EndFunc   ;==>InetGetHeader
Edited by guinness

UDF List:

  Reveal hidden contents

Updated: 22/04/2018

Posted (edited)

Yeah i already had found that function.

I made this.

#include <Constants.au3>
FileName("http://microsoft.com")
Func FileName($url)
$http = ObjCreate("winhttp.winhttprequest.5.1")
$http.Open("POST", $url, 1)
$http.Send()
$http.WaitForResponse
MsgBox($MB_SYSTEMMODAL,"Header",$http.GetResponseHeader("Content-Type"))
EndFunc

I can easly say though that your function is much much faster than mine for big files.

Edited by ileandros

I feel nothing.It feels great.

Posted

So does it work for you?

UDF List:

  Reveal hidden contents

Updated: 22/04/2018

Posted (edited)

Yes it works but it is not excaclty what i wanted to achive.

I have made a InetGet function and i want to get the Header of it so i can take the type of it and use it to set the name of the file before downloading. And thats because when i download a file and don't set the type of the file correctly (example: download an .exe, if the type of the file is .txt or something else) it wont be downloaded correctly.

Edit: and the name should be set before downloading

Edited by ileandros

I feel nothing.It feels great.

Posted

You've made an InetGet function? Care to share it with us please.

I think what you are looking for isn't as easy as you think it is. The header example displays the content-type, it just doesn't return it as you want in plain English as "This is a .txt file."

Did you check the WinHttp functions as well whilst searching?

UDF List:

  Reveal hidden contents

Updated: 22/04/2018

Posted (edited)

Ye there you go

Global $Proor = @DesktopDir & "\test.exe"
FileDownload("http://download.thinkbroadband.com/5MB.zip",$Proor)
Func FileDownload($url, $SavePath)
Local $xml ,$stream
$xml = ObjCreate("Microsoft.XMLHTTP"); Corrected from winhttp.winhttprequest.5.1 for faster dl
$stream = ObjCreate("Adodb.Stream")
$xml.Open("GET", $url, 0)
$xml.Send
ConsoleWrite($xml.GetAllResponseHeaders())
$stream.Type = 1
$stream.Open
$stream.write($xml.ResponseBody)
$stream.SaveToFile($SavePath)
$stream.Close
EndFunc

So a stringreplace function would help me or something like that? I have never used string functions in autoit.

I will get crazy

Edited by ileandros

I feel nothing.It feels great.

Posted

The code doesn't work.

UDF List:

  Reveal hidden contents

Updated: 22/04/2018

Posted (edited)

Already am.

Anyway, besides that I didn't understand your point about String functions. You've never used StringInStr or StringReplace?

Edited by guinness

UDF List:

  Reveal hidden contents

Updated: 22/04/2018

Posted (edited)

This was a part of the function but i copied the code i posted above and it runs fine.

What is your console write error?

P.s $stream.SaveToFile($SavePath) won't work if an test.exe already exists in your desktop.

Try giving it a different path

Edit John got a point. If dl is not completed it won't display it. Try adding a dl link from a small file.

The link i have in the example is a small 5mb link for download test(nothing)

Edited by ileandros

I feel nothing.It feels great.

Posted

I just don't get what is wrong with my example? It doesn't download the file and it retrieves the content-type albeit not how you are expecting it.

UDF List:

  Reveal hidden contents

Updated: 22/04/2018

Posted

ileandros,

Ty this

Global $Proor = @DesktopDir & "\test.exe"
FileDownload("http://download.thinkbroadband.com/5MB.zip", $Proor)
Func FileDownload($url, $SavePath)
    filedelete($savepath)                                               ; <----- added for successive runs
    Local $xml, $stream
    $xml = ObjCreate("Microsoft.XMLHTTP")                               ; Corrected from winhttp.winhttprequest.5.1 for faster dl
    $stream = ObjCreate("Adodb.Stream")
    $xml.Open("GET", $url, 0)
    $xml.Send
    local $resp_headers = $xml.GetAllResponseHeaders()
    ConsoleWrite($resp_headers & @lf)

    local $a10 = stringregexp($resp_headers,'Content-Type.*/(.*)',3)    ;  <----- This only works if "Content-Type" is always present
    if @error = 0 then
        ConsoleWrite('File type is ' & $a10[0] & @LF)
    Else
        ConsoleWrite('File type not found' & @LF)
    endif

    $stream.Type = 1
    $stream.Open
    $stream.write($xml.ResponseBody)
    $stream.SaveToFile($SavePath)
    $stream.Close
EndFunc   ;==>FileDownload

kylomas

Forum Rules         Procedure for posting code

"I like pigs.  Dogs look up to us.  Cats look down on us.  Pigs treat us as equals."

- Sir Winston Churchill

Posted

Or better, Guinness's example adapted

#include <Constants.au3>

TCPStartup()
local $str = InetGetHeader('http://mirrors.kernel.org/gentoo/releases/amd64/10.1/livedvd-amd64-multilib-10.1.iso')
local $a10 = stringregexp($str,'Content-Type.*/(.*)',3) ;  <----- This only works if "Content-Type" is always present
if @error = 0 then
    ConsoleWrite('File type is ' & $a10[0] & @LF)
Else
    ConsoleWrite('File type not found' & @LF)
endif
TCPShutdown()

Func InetGetHeader($sURL)
    Local Const $aOSArch[2] = ['32', '64']
    Local Const $sUserAgent = 'AutoIt/' & @AutoItVersion & ' (Windows NT ' & _
            RegRead('HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows NT\CurrentVersion\', 'CurrentVersion') & _
            '; Win' & $aOSArch[@AutoItX64] & '; x' & $aOSArch[@AutoItX64] & ' & ) Version/' & @AutoItVersion
    Local Const $sHost = StringRegExpReplace($sURL, '.*://(.*?)/.*', '\1')
    Local Const $sPage = StringRegExpReplace($sURL, '.*://.*?(/.*)', '\1')
    Local Const $sSend = 'HEAD ' & $sPage & ' HTTP/1.1' & @CRLF & _ ; HEAD / GET / POST
            'Host: ' & $sHost & @CRLF & _
            'User-Agent: ' & $sUserAgent & @CRLF & _
            'Referer: ' & $sHost & @CRLF & _
            'Connection: close ' & @CRLF & @CRLF
    Local $sReturn = ''

    Local Const $sIPAddress = TCPNameToIP($sHost)
    If $sIPAddress == '' Then
        Return SetError(@error, 0, $sReturn)
    EndIf

    Local $iSocket = TCPConnect($sIPAddress, 80)
    If Not $iSocket Then
        Return SetError(@error, 0, $sReturn)
    EndIf
    If TCPSend($iSocket, $sSend) = 0 Then
        TCPCloseSocket($iSocket)
        Return SetError(@error, 0, $sReturn)
    EndIf

    Local Const $TCP_MAXLEN = 16
    Do
        $sReturn &= TCPRecv($iSocket, $TCP_MAXLEN)
    Until @error
    TCPCloseSocket($iSocket)

    Return SetError($sReturn == '', 0, $sReturn)
EndFunc   ;==>InetGetHeader

kylomas

Forum Rules         Procedure for posting code

"I like pigs.  Dogs look up to us.  Cats look down on us.  Pigs treat us as equals."

- Sir Winston Churchill

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
  • Recently Browsing   0 members

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