Thank you very much for the effort. What you have described works, except for pdf files.
A bigger problem is that the socket I'm trying to read returns data only if I am in debug mode. (It works fine if I go step by step debugging the code untill I pass the Socket.Flush function)
Do you have any idea?
I am using the following code to make contact to the socket en to read from it:
sDownloadUrl = "
application = "GET "+sTemp+" HTTP/1.1"
Socket.Connect( sock, sDownloadUrl, 80 ) // Connection with host
Socket.Write( sock, application ) // Patch to the correct application
Socket.Write( sock, Web.CRLF ) // Line Feed
Socket.Write( sock, "HOST: "+sDownloadUrl ) // needed for protocol http/1.1
Socket.Write( sock, Web.CRLF ) // Line Feed
Socket.Write( sock, Web.CRLF ) // Line Feed
Socket.Flush( sock ) // Flushes the output buffer of the specified Socket.
iIndex = Str.Locate(sTemp, "OC-")
sFileName = sTemp[iIndex:length(sTemp)]
while ( !IsError( status = Socket.ReadBytes( sock ) ) ) //Reading the information from the response
Socket.Write( sock, "" )
strBytes = Bytes.GetString(status, 0)
iIndex = Str.LocateI( strBytes, Web.CRLF+Web.CRLF )
if iIndex && bHeaderDone
sHTTPHeader = strBytes[1:iIndex + 1]
sBody = strBytes[iIndex + 4:length(strBytes)]
lResult = Str.Elements(strBytes, Web.CRLF)
for sTemp in lResult
if Str.LocateI( sTemp, "Content-Length:")
len = Str.StringToInteger( .Strip(sTemp, "Content-Length:", undefined) )
end
if Str.LocateI( sTemp, "Content-Type:")
mimeType = .Strip(sTemp, "Content-Type:", undefined)
end
end
headers = Str.Format( "Content-Type: application/octet-stream%1", Web.CRLF )
headers += Str.Format( "Accept-ranges: bytes%1Content-Type: %2%1Content-Length: %3%1", Web.CRLF, mimeType, len )
if !Str.LocateI( sHTTPHeader, "Content-Disposition")
if ( UseHeaderHint( r ) )
headers += Str.Format( "Content-Disposition: attachment; filename*=utf-8'%1%2%2", sFileName, Web.CRLF )
else
headers += Str.Format( "Content-Disposition: attachment; filename=%1%2%2", sFileName, Web.CRLF )
end
end
sTemp = "C:\temp\test"
File.Create(sTemp)
f = File.Open(sTemp, File.WriteBinMode)
File.WriteBytes(f, Bytes.NewFromString( sBody ))
bHeaderDone = False
elseif Length(status)
File.WriteBytes(f, status)
end
end
Socket.Close( sock )
File.Close( f )
Bytes bTemp
fr = File.Open( sTemp, File.ReadBinMode )
Socket.Write( ctxout, headers )
if ( !IsError( fr ) )
for ( bTemp = File.ReadBytes( fr, 30720 ); \
bTemp != File.E_Eof; \
bTemp = File.ReadBytes( fr, 30720 ) )
Socket.Write( ctxout, bTemp )
end
end
File.Close( fr )
Socket.Close( ctxout )( ctxout )