Jump to content

Problem with InetGetSize


dfmatt
 Share

Recommended Posts

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

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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
Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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?

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

  • 1 month later...

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...