West Wind Internet and Client Tools
WWHTTP:HTTPGetEx getting HTTP 6 - Win32 API: The handle is invalid. error on second call.
Gravatar is a globally recognized avatar based on your email address. WWHTTP:HTTPGetEx getting HTTP 6 - Win32 API: The handle is invalid. error on second call.
  Pat
  All
  Jul 18, 2018 @ 10:30am

I want to open up the connection one and make multiple request of a file.

oHTTP = CREATEOBJECT("wwHTTP")
lnResult = oHTTP.httpconnect("www.west-wind.com")
** Check for HTTP protocal errors.
IF lnResult # 0
	messagebox(STR(lnResult) + " - " + oHTTP.cErrorMsg,0+16,"HTTP Error")
	RETURN .F.
ENDIF

*** Initialize the variables that will be filled by HTTPGetEx
lcHTML = ""
lnText=0
lnResult = oHTTP.HTTPGetEx("/files/wwipstuff.zip",@lcHTML,@lnText,,;
							"c:\temp\wwipstuff.zip")
** Check for HTTP protocal errors.
IF lnResult # 0
   messagebox(STR(lnResult) + " - " + oHTTP.cErrorMsg,0+16,"HTTP Error")
	llReturn = .F.
ENDIF

lcHTML = ""
lnText=0

************* ON THE NEXT STATEMENT IS WHERE I GET ERROR   ********

lnResult = oHTTP.HTTPGetEx("/files/wwipstuff.zip",@lcHTML,@lnText,,;
							"c:\temp\wwipstuff_1.zip")
** Check for HTTP protocal errors.
IF lnResult # 0
   messagebox(STR(lnResult) + " - " + oHTTP.cErrorMsg,0+16,"HTTP Error_1")
	llReturn = .F.
ENDIF

Gravatar is a globally recognized avatar based on your email address. re: WWHTTP:HTTPGetEx getting HTTP 6 - Win32 API: The handle is invalid. error on second call.
  Rick Strahl
  Pat
  Jul 19, 2018 @ 08:55am

Http requests are stateless and you can't make multiple calls on the same connection. You need to reconnect - in your case you will have to call HttpConnect() again.

However, I highly recommend you don't use HttpGetEx() - this is meant as an internal method that is used by the higher level HttpGet() method. HttpGet() can do all the things that HttpGetEx() does with much less code and proper encapsulation of the entire HTTP call sequence. Using HttpGet() you won't have to reconnect explicitly since the high level call does it for you.

+++ Rick ---

© 1996-2024