Jump to content
Sign in to follow this  
dfmatt

Problem with InetGetSize

Recommended Posts

dfmatt

I am trying to use InetGetSize to return the size of a file on my server.

I have checked the page headers and they are

HTTP/1.x 200 OK

Date: Wed, 14 Jan 2009 13:31:44 GMT

Server: Apache

X-Powered-By: PHP/5.2.4-2ubuntu5.4

Content-Length: 117

Keep-Alive: timeout=15, max=100

Connection: Keep-Alive

Content-Type: text/html

so it should be returning something, but it always gives me 0 and sets @error to 1.

The code is this,

$size_groups = InetGetSize ( 'https://mydomain.net/index.php' )
MsgBox ( 0 , "" , $size_groups )

Does anyone know what might be going wrong?

Thanks

Share this post


Link to post
Share on other sites
dfmatt

It wouldn't be a proxy because there isn't one on my machine or on the server.

How could HTTPS cause a problem?

The HTTP UDF doesn't seem to have a way to monitor progress of download which is the whole reason I want to use InetGetSize the function to just get a file (InetGet I think) works fine for my file.

Share this post


Link to post
Share on other sites
dfmatt

Ah ok. But wouldn't the fact that InetGet supports HTTPS mean that InetGetSize would too?

Share this post


Link to post
Share on other sites
weaponx

I see you are pointing to a php file, what type of output does it generate?

Share this post


Link to post
Share on other sites
dfmatt

The page just says "Hello world" there is no PHP there at the moment.

Share this post


Link to post
Share on other sites
weaponx

Try this:

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

;$oHTTP = ObjCreate('winhttp.winhttprequest.5.1')
$oHTTP = ObjCreate("MSXML2.XMLHTTP")
$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("+<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<< Content-Length" & @CRLF)
$ContentLength = $oHTTP.GetResponseHeader("Content-Length") 
ConsoleWrite($ContentLength & @CRLF)

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

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

exit
;If status OK then save file
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

Share this post


Link to post
Share on other sites
dfmatt

Thanks for the replies.

Well it works for that first file, but now I'm trying it on a real file.

It's a Perl script being executed by the server and the output is blank.

The header I put in my original post is from that same Perl script.

Share this post


Link to post
Share on other sites
weaponx

Did you try the script I just posted? If it works then Content-Length will have the file size in bytes.

Share this post


Link to post
Share on other sites
dfmatt

Yes that was what I was referring to.

Your scripts gave me the content-length for the hello world file, but not for the executed perl script.

Share this post


Link to post
Share on other sites
weaponx

Yes that was what I was referring to.

Your scripts gave me the content-length for the hello world file, but not for the executed perl script.

Does you perl script redirect or does it directly output the header?

Share this post


Link to post
Share on other sites
weaponx

When I run the test script using the "MSXML2.XMLHTTP" object I get the correct value for the test link. When I use it on a PHP file its empty. If I switch to the "winhttp.winhttprequest.5.1" object it works.

Share this post


Link to post
Share on other sites
dfmatt

That was what I was doing wrong, I hadn't tried using the winhttp.winhttprequest.5.1 object.

Am now and its working for me too.

Thanks a lot!

Share this post


Link to post
Share on other sites
CaptainGadget

That was what I was doing wrong, I hadn't tried using the winhttp.winhttprequest.5.1 object.

Am now and its working for me too.

How did you end up resolving the problem with InetGetSize? Were you able to get it to work with an https link? I have no problems with InetGet, only InetGetSize.

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  

×