Results 1 to 4 of 4

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

  1. #1

    Thread Starter
    Member
    Join Date
    Dec 2015
    Posts
    38

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

    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-www-form-urlencoded"
        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

  2. #2
    PowerPoster wqweto's Avatar
    Join Date
    May 2011
    Location
    Sofia, Bulgaria
    Posts
    6,167

    Re: WinHttpRequest - errors like 'method cannot be called until open/send has been ca

    Try objHTTP.Send CVar(Credentials_s)

    This is a known bug with Send method where the argument cannot have VT_BYREF flag set i.e. cannot be an l-value (like a plain variable) and must be an expression of some form.

    cheers,
    </wqw>

  3. #3

    Thread Starter
    Member
    Join Date
    Dec 2015
    Posts
    38

    Re: WinHttpRequest - errors like 'method cannot be called until open/send has been ca

    Thanks, wq. I tried enclosing the variable with CVar, but the properties are still empty.

    This has to be the way in which the credentials are being delivered. The Credentials_s parameter with Send, is actually redundant because SetCredentials is already used. However, I tried removing the SetCredentials call ; and tried leaving it and removing the CVar( Credentials_s ) parameter from the Send.

    I DID notice that, after Open is executed, the url_s is considered invalid. (I can link to it, in a browser). I'll try this with a different url.
    Last edited by VBExplorer12; Mar 11th, 2021 at 12:56 PM.

  4. #4

    Thread Starter
    Member
    Join Date
    Dec 2015
    Posts
    38

    Re: WinHttpRequest - errors like 'method cannot be called until open/send has been ca

    Got it. The problem is that the tool that I'm using - VBSedit - requires the temporary command line parameters to be separated by spaces. I had them separated by commas and spaces.

    So the Url_s was being interpreted as something like " 'www.thissite.com', "

    Thanks for the tip, wq. Noted for the future.

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width