From: hpeter on 6 Dec 2006 18:51 Basic question: Need to upload files using HTTP (not FTP) with monitoring progress uploaded. Found so many articles, but the pinciple is explained here: How To Upload Files to the Internet Information Server: http://support.microsoft.com/kb/184352. I have a routine to do that using the FTP classess with some switches to connect passive or not. However, for some clients with special firewall configuration and proxy server this aproach does not work, and the requirement for my application is to do it with pure HTPP. The IT guys will not accomodate my app. I also implemented a routine for downloading files using HTTP with progress monitoring downloading (following recomendations at: http://support.microsoft.com/kb/234913/en-us) and some discussion in this NG. However, I have not been successful in passing beyond HTTPSendRequest step as depicted in the microsoft article, and following the hierarchical sequence as stated in http://msdn.microsoft.com/library/default.asp?url=/library/en-us/wininet/wininet/appendix_a_hinternet_handles.asp The following routine fails in HTTPSendRequest: ..... LOCAL DWSize AS DWORD LOCAL zBuffer AS PSZ LOCAL zpBUFFER AS PTR LOCAL pInter, pIconn, pHTTPConn AS PTR pInter := InternetOpen(PSZ(_CAST,"KilletSoft"),INTERNET_OPEN_TYPE_PRECONFIG,NULL_PSZ,; NULL_PSZ,INTERNET_SERVICE_URL) pIConn := InternetConnect( pInter, PSZ(_CAST, "http://localhost" ), ; INTERNET_DEFAULT_HTTP_PORT, PSZ(_CAST, "user" ), ; PSZ(_CAST, "pwd" ), INTERNET_SERVICE_HTTP, INTERNET_NO_CALLBACK, 0 ) pHTTPConn := HttpOpenRequest( pIConn, String2Psz( "PUT"), ; String2Psz("filename_to_be_created_at_the_server.txt"), ; String2Psz(HTTP_VERSION), ; NULL_PSZ, ; NULL_PSZ, ; INTERNET_FLAG_DONT_CACHE, ; 0) zBuffer := String2Psz("Testing Some data " + Time24()) dwSize := PszLen( zBuffer ) MemCopy( zpBuffer, @zBuffer, dWSize ) IF .NOT. HttpSendRequest( pHTTPConn, NULL_PSZ, 0,zpBuffer,PszLen( zBuffer )) // Here is where I get stuck. HTTPSendReqeust return FALSE ENDIF I tried also the variation of using the WinInet function HTTPSendRequestEx and InternetWriteFile for uploading chunks of data, but again, I can not pass beyond HTTPSendRequestEx Any hint? Has anyone used Hernando
From: Norbert Kolb on 7 Dec 2006 09:49 Hello Hernado, I think, you must not use http in the URL in InternetConnect. May be that is all. Have a look on your mail. I sent you a sample wich will do the job. > > pIConn := InternetConnect( pInter, PSZ(_CAST, "http://localhost" ), ; > INTERNET_DEFAULT_HTTP_PORT, PSZ(_CAST, "user" ), ; > PSZ(_CAST, "pwd" ), INTERNET_SERVICE_HTTP, INTERNET_NO_CALLBACK, 0 ) > Norbert
From: hpeter on 7 Dec 2006 10:10 > I think, you must not use http in the URL in InternetConnect. May be that is > all. It does not make any difference. I have used the same sequence syntax with InternetReadFile and works up to that point. I will take a look at the sample. Thank you Hernando
From: Sherlock on 7 Dec 2006 10:51 Hernado, I use this for HTTP download with progress bar... Phil McGuinness ------------------------- METHOD GetLowLevel( cFile, cExportPath, nSize ) AS LOGIC CLASS cHttp LOCAL hfFTP AS PTR LOCAL lRet := FALSE AS LOGIC LOCAL nBuffSize AS DWORD LOCAL hfLocal, pBuff AS PTR LOCAL oFTPProgress AS _dFTPProgress LOCAL nStart AS REAL4 hfFTP := SELF:OpenFile(cFile, GENERIC_READ) oFTPProgress := _dFTPProgress{ _Shell() } oFTPProgress:show() oFTPProgress:oDCFTPStatus:value := "Connection to www.Sherlock.com.au" oFTPProgress:Caption := "HTTP download active" pBuff := MemAlloc( HTTP_MAX_BUFF_SIZE ) // IF (hfFTP != NULL_PTR .AND. pBuff != NULL_PTR) hfLocal := FCreate(cExportPath + cFile) // IF hfLocal != NULL_PTR nBuffSize := HTTP_MAX_BUFF_SIZE lRet := TRUE // nStart := Seconds() oFTPProgress:oDCFTPBar:Range := Range{1, Integer(nSize/nBuffSize) + 2 } oFTPProgress:oDCFTPBar:Show() // DO WHILE nBuffSize = HTTP_MAX_BUFF_SIZE IF ! InternetReadFile( hfFTP, pBuff, HTTP_MAX_BUFF_SIZE, @nBuffSize ) MessageBox(0, InetErrorMsg(GetLastError()), String2Psz("ERROR"), MB_OK) EXIT ENDIF IF nBuffSize> 0 FWrite3( hfLocal, pBuff, nBuffSize ) ENDIF oFTPProgress:oDCFTPStatus2:value := NTrim((Seconds() - nStart ) / 60) + ' Minutes/secs' // oFTPProgress:oDCFTPBar:Advance(1) GetAppObject():Exec(EXECWHILEEVENT) ENDDO FClose( hfLocal ) oFTPProgress:oDCFTPBar:Position := 0 SELF:CloseFile(hfFTP) // oFTPProgress:oDCFTPStatus:value := "File received" ELSE SELF:Error := ERROR_INTERNET_INVALID_OPERATION oFTPProgress:oDCFTPStatus := "Could not receive file " + cFile ENDIF ENDIF oFTPProgress:EndDialog() oFTPProgress := NULL_OBJECT // MemFree( pBuff ) // RETURN lRet
From: hpeter on 7 Dec 2006 11:50 Thanks for sharing this code. I have something similar for downloading. What I need also is for UPloading files via HTPP, ideally not using POST since I will uploading big files (3-6 MB each, 4-8 files per session, per user). Hernando Sherlock wrote: > Hernado, > > I use this for HTTP download with progress bar... > > Phil McGuinness > ------------------------- > > METHOD GetLowLevel( cFile, cExportPath, nSize ) AS LOGIC CLASS cHttp > > LOCAL hfFTP AS PTR > LOCAL lRet := FALSE AS LOGIC > LOCAL nBuffSize AS DWORD > LOCAL hfLocal, pBuff AS PTR > LOCAL oFTPProgress AS _dFTPProgress > LOCAL nStart AS REAL4 > > > hfFTP := SELF:OpenFile(cFile, GENERIC_READ) > > oFTPProgress := _dFTPProgress{ _Shell() } > oFTPProgress:show() > oFTPProgress:oDCFTPStatus:value := "Connection to > www.Sherlock.com.au" > oFTPProgress:Caption := "HTTP download active" > > pBuff := MemAlloc( HTTP_MAX_BUFF_SIZE ) > // > IF (hfFTP != NULL_PTR .AND. pBuff != NULL_PTR) > hfLocal := FCreate(cExportPath + cFile) > // > IF hfLocal != NULL_PTR > nBuffSize := HTTP_MAX_BUFF_SIZE > lRet := TRUE > // > nStart := Seconds() > oFTPProgress:oDCFTPBar:Range := Range{1, > Integer(nSize/nBuffSize) + 2 } > oFTPProgress:oDCFTPBar:Show() > // > DO WHILE nBuffSize = HTTP_MAX_BUFF_SIZE > IF ! InternetReadFile( hfFTP, pBuff, HTTP_MAX_BUFF_SIZE, @nBuffSize ) > MessageBox(0, InetErrorMsg(GetLastError()), String2Psz("ERROR"), > MB_OK) > EXIT > ENDIF > IF nBuffSize> 0 > FWrite3( hfLocal, pBuff, nBuffSize ) > ENDIF > oFTPProgress:oDCFTPStatus2:value := NTrim((Seconds() - nStart ) / 60) > + ' Minutes/secs' > // > oFTPProgress:oDCFTPBar:Advance(1) > GetAppObject():Exec(EXECWHILEEVENT) > ENDDO > FClose( hfLocal ) > oFTPProgress:oDCFTPBar:Position := 0 > SELF:CloseFile(hfFTP) > // > oFTPProgress:oDCFTPStatus:value := "File received" > ELSE > SELF:Error := ERROR_INTERNET_INVALID_OPERATION > oFTPProgress:oDCFTPStatus := "Could not receive file " + > cFile > ENDIF > ENDIF > oFTPProgress:EndDialog() > oFTPProgress := NULL_OBJECT > // > MemFree( pBuff ) > // > RETURN lRet
|
Next
|
Last
Pages: 1 2 Prev: Using SetTerBuffer en GetTerBuffer of the TER Text Editor Next: FabPaintLib |