Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

WinHttpRequest - errors like 'method cannot be called until open/send has been called 2

Status
Not open for further replies.

Don Child

Programmer
Apr 4, 2003
64
US
Hi,

After both Opening and Sending a request, some of the propertes of a WinHttpRequest are displaying errors.


Code:
On Error Resume Next

    Set objHTTP = CreateObject( "WinHttp.WinHttpRequest.5.1" )
    Request_s = "GET"
    
    objHTTP.Open Request_s, Url_s, False
    objHTTP.setRequestHeader "Content-type", "application/x-[URL unfurl="true"]www-form-urlencoded"[/URL]
    objHTTP.SetCredentials User_s, Password_s, HTTPREQUEST_SETCREDENTIALS_FOR_SERVER
    objHTTP.Send Credentials_s
   '// BELOW, Status (and ResponseBody and ResponseText, etc.) are showing that the request hasn't been sent, even though it just was.
   '// ALSO, the Option property says that the Open method must be called.
    Status_n = objHTTP.Status
    Status_Text_s = objHTTP.StatusText
    HTML_s = objHTTP.ResponseText
 
StatusText isn't a variable. However I may be wrong though.

VBS newbie here.

Sincerely,
Bob Space
 
I would suggest that the removal of 'On Error Resume Next" and stepping[sup]1[/sup] through your code will help immeasurably in identifying what your problem is

[sup]1[/sup]Assuming you have access to a script debugging tool
 
Yeah, that's meant to go where the script could be wrong. Not at the beginning. However I do sorta see what they're going for.

Sincerely,
Bob Space
 
>that's meant to go where the script could be wrong

Actually, I'd advise that you only ever use this when you know exactly what errors may subsequently arise and handling them yourself. And disable it as soon as you are done with your handling. Using it to mask errors in blocks of code simply because you don't know what those errors might be and it seems easiest to just ignore them leads to problems - like the one being experienced here.
 
Thanks for the advice, I've used it before, and I will in advance.

Sincerely,
Bob Space
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top