none
Invalid Parameters when using XMLHTTP.6.0 and POST method. RRS feed

  • Question

  • We have a small VB6 program that uses XMLHTTP object to send some form data back to the server.  In addition, we were attempting to use the 6.0 version of the MSXML routines.  It seems that is the version recommended.

    Everything works fine if we use the "GET" method and add the parameters to the end of the URL. 

    However, when using the "POST" method we keep getting "invalid parameter" when call the "send" method with the parameter list as the message body in the "send".

    Interestingly if we use the previous versions of XMLHTTP everything works great with either a "POST" or a "GET".

    What are we missing here?  Is there some API change to the "send" parameter we are overlooking? 

    For reference the code is quite simple:

     

    Dim objXMLRequest As Object
    Dim BodyOfRequest as String
    BodyOfRequest = "state=" & URLEncode(State) _    
       & "&sq=" & URLEncode(SequenceNumber)
    Set objXMLRequest = CreateObject("MSXML2.XMLHTTP.6.0")
    Call objXMLRequest.open("POST", BaseURL , False)
    Call objXMLRequest.setRequestHeader("Content-Type", "application/x-www-form-urlencoded")
    objXMLRequest.setRequestHeader "User-Agent", "Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 6.0)"
    call objXMLRequest.send (BodyOfRequest)
    
    

     

    If we change to "MSXML2.XMLHTTP.3.0" it works.

    Searches on this problem have come up pretty empty.  So hopefully someone has an idea.

    Thanks in advance for your help.  It is appreciated.

     


    Bernie
    Thursday, June 9, 2011 3:41 AM

Answers

  • Pure speculation - You appear to be working in an environment that allows strong typing (VBA in Office?) and that the type of the parameter for the send is defined as a Variant when examining the object and that you have dimensioned BodyOfRequest as String.  Maybe the 3.0 code performs a typecast and the 6.0 does not.  Of course, I would have expected that to cause a "type mismatch" error, but ...

    It wouldn't take much to change the type to Variant, so I'd give that a shot.


    Tom Lavedas
    • Marked as answer by Bernard_J_L Thursday, June 9, 2011 4:13 PM
    Thursday, June 9, 2011 12:57 PM
    Moderator

All replies

  • Pure speculation - You appear to be working in an environment that allows strong typing (VBA in Office?) and that the type of the parameter for the send is defined as a Variant when examining the object and that you have dimensioned BodyOfRequest as String.  Maybe the 3.0 code performs a typecast and the 6.0 does not.  Of course, I would have expected that to cause a "type mismatch" error, but ...

    It wouldn't take much to change the type to Variant, so I'd give that a shot.


    Tom Lavedas
    • Marked as answer by Bernard_J_L Thursday, June 9, 2011 4:13 PM
    Thursday, June 9, 2011 12:57 PM
    Moderator
  • Tom, thanks for the quick response. 

    Your suggestion worked perfectly!  Changing the variable to type "Variant" worked as did doing a type cast of the string to "Variant" before the call.

    There must be a change between the 3.0 and 6.0 version since we have seen tons of code with that parameter as a "String" with no problems. 

    You efforts are really appreciated.

    Thanks.

     

     

    Thursday, June 9, 2011 4:13 PM
  • This just saved my butt!  Good tip on the strong typing Mr. Lavedas.
    Monday, May 23, 2016 8:11 PM
  • This solved my problem as well:

    1. Created an additional variable as a Variant
    2. Assigned the Variant the value of the String that was failing to send in the POST
    3. Used the Variant variable in the Post statement instead of the String. 

    Thanks, Tom <g class="gr_ gr_9 gr-alert gr_spell gr_inline_cards gr_run_anim ContextualSpelling ins-del multiReplace" data-gr-id="9" id="9">Levedas</g>! Didn't find this <g class="gr_ gr_10 gr-alert gr_spell gr_inline_cards gr_run_anim ContextualSpelling ins-del multiReplace" data-gr-id="10" id="10">reponse</g> <g class="gr_ gr_11 gr-alert gr_spell gr_inline_cards gr_run_anim ContextualSpelling ins-del multiReplace" data-gr-id="11" id="11">elasewhere</g>, this one was a challenge!

        Dim varStringToSend As Variant
     
        On Error GoTo Err_SendingAcknowledgement
        
        '-- Values to add to the header in order to connect to the Ack JSON Services: none
        
        Set objRequest = CreateObject("MSXML2.XMLHTTP")
        
        strURL = "http://....com:41801/appl/api/ack"
        strJSONBodyString = AckJSONBodyString
        lngServiceResponseCode = -1
        blnAsync = True
    
        varStringToSend = strJSONBodyString
    
        With objRequest
            .Open "POST", strURL, blnAsync
            .SetRequestHeader "Content-Type", "application/json"
            .Send varStringToSend
    
    
    
    
    

    Tuesday, February 12, 2019 2:42 PM