none
XMLHTTP.send method not sending body when opened with "GET" instead of "POST" RRS feed

  • Question

  • I am trying to make a service call from an Excel spreadsheet. 

    Dim sURL as String   
    Dim sReqBody as String
    Dim httpReq As New ServerXMLHTTP60
    
    '// Code to set URL and build body omitted
    '// Debug.Print does show that the strings are correct
    
    httpReq.Open "get", sURL, False
    xmlhtp.send sReqBody
    

    I can see the response the server is receiving, and the sReqBody is not included.  If I change the open to "post" instead of "get", the sReqBody is included, but the server rejects the message because the "post" method was never implemented.  

    I cannot change the server, just my spreadsheet.  Is there any way to make the "get" method include the body?  I can't see any reason it isn't including it in the documentation.

     

    Tuesday, December 13, 2011 7:47 PM

All replies

  • Not sure what you mean by "the 'post' method was never implemented", but I had a similar problem and resolved it by setting the Request Header correctly.

    example:

    httpReq.Open "POST", sURL, False
    httpReq.setRequestHeader "Content-type", "application/xml"
    httpReq.send strXML

    In my case, I had to use "application/xml" for the Content-type. You may have to use "text/xml".

    Hope this helps.

    Wednesday, December 14, 2011 3:56 AM
  • That's exactly what I did at first, however that returns a 501 error.  The service does not support POST, only GET. Thus, I am trying to figure out how to send a request body with the GET method using HTTP.

    Here's the error as returned by the service:

    HTTP/1.1 501 Not Implemented

     



    Zyanthia
    Wednesday, December 14, 2011 12:48 PM
  • Did you try something like this:

    Dim sURL As String
    Dim sReqBody As String
    
    sURL = "http://www.YourDomainName.com"
    sReqBody = "your text here"
    
    Set objHTTP = CreateObject("MSXML2.ServerXMLHTTP")
       
    objHTTP.Open "POST", sURL, False
    
    objHTTP.setRequestHeader "User-Agent", "Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.0)"
    
    objHTTP.send (sReqBody)
    
    
    Set objHTTP = Nothing
    


    Hope this helps,

     


    Daniel van den Berg | Washington, USA | "Anticipate the difficult by managing the easy"
    Wednesday, January 11, 2012 11:33 PM
    Moderator
  • For the third time in this thread (four if you include the title), I cannot use the "POST" method.  It must be "GET".   The post method was not implemented on the server, and trying to use POST will return an error 501.   I cannot change the server, I can only change the system calling the server.

    To summarize: 

    1)  The Open function must be called with method of "GET", I do not have an option here.  objHTTP.Open "GET", sURL, False 

    2)  The request body must contain the text to be translated. objHTTP.send (sReqBody) does not send the body. 

    Failure to do either of these 2 results in the process not working.  The only implementation I was able to do was to create my own HTTP service using Java, because nothing I did in the Microsoft world would make the two requirements work, even though there is nothing in the documentation that states the request body is only sent when the connection is opened with the "POST" method.


    Zyanthia
    Wednesday, January 25, 2012 12:30 PM
  • Hi Zyanthia,

     

    Thank you for your feedback. Did you test my code example, note that I use a different object then you posted in original question.

    I use the MSXML2.ServerXMLHTTP Object, while you use the ServerXMLHTTP60 Object.

     

    I am not sure if it makes any difference, but please let me know and confirm that my code isn't working as well.

     

    Hope this helps,

     


    Daniel van den Berg | Washington, USA | "Anticipate the difficult by managing the easy"
    Thursday, January 26, 2012 4:58 AM
    Moderator
  • I did try your option to use the MSXML2.ServerXMLHTTP object.

    "HTTP/1.1 501 Not Implemented" error is still returned when object.open uses "POST".

    Envelope body still not being delivered when the object.open uses "GET".

    I think the root of the problem is most services either post or get, but this service does both.  The service accepts B64 input as if that had been the data from a POST request, then creates a file which is returned as if a GET request had been submitted on that file.  

    Maybe I just need a G(et)(p)OST protocol.   This is starting to sound like a bad movie.  

    Anyway, I could never figure out how to make it work from the spreadsheet directly, so I save the spreadsheet contents to a text file.  I then run a java app that reads the text file, and submits to the server using the GOST protocol.  

    Here's the code (with specifics hidden).  

    Option Explicit
    
    Sub MySub
        Dim iRow As Integer
        Dim sURL As String
        Dim sEnvelope As String
        Dim xmlhtp As MSXML2.ServerXMLHTTP
        Set xmlhtp = CreateObject("MSXML2.ServerXMLHTTP")
        sURL = "MyWebServiceURL"
    
        sEnvelope = "<?xml version=""1.0"" encoding=""utf-8""?>"
        sEnvelope = sEnvelope & "<soap:Envelope xmlns:soap=""http://schemas.xmlsoap.org/soap/envelope/"" xmlns:xsd=""http://www.w3.org/2001/XMLSchema"" xmlns:xsi=""http://www.w3.org/2001/XMLSchema-instance"">"
        sEnvelope = sEnvelope & "<soap:Body xmlns:m=""MySchema"">"
        sEnvelope = sEnvelope & "<m:MyWebService>"
        sEnvelope = sEnvelope & "<m:MyInputData MyOption1=""n"" MyOption2=""n"" MyOption3=""xsd:base64Binary"">"
        
        iRow = 2
        Do While Len(Cells(iRow, 1)) > 0
            sEnvelope = sEnvelope & Cells(iRow, 1) & vbCrLf
            iRow = iRow + 1
        Loop
        
        sEnvelope = sEnvelope & "</m:MyInputData>"
        sEnvelope = sEnvelope & "</m:MyWebService>"
        sEnvelope = sEnvelope & "</soap:Body>"
        sEnvelope = sEnvelope & "</soap:Envelope>"
    
        '//***********************************************//
        '// The server being called does not support Post,//
        '// trying to use Post will result in a 501 error.//
        '//***********************************************//
        xmlhtp.Open "Get", sURL, False        
    
        xmlhtp.setRequestHeader "User-Agent", "My Testing"
        xmlhtp.setRequestHeader "Host", "MyHost:MyPort"
    
        xmlhtp.send sEnvelope
    
        Cells(2, 2) = xmlhtp.responseText
           
        Set xmlhtp = Nothing
    End Sub
    


    Zyanthia
    Thursday, January 26, 2012 2:02 PM
  • I don't know if this is the issue but I was also getting a 501 when using MSXML2.ServerXMLHTTP object.

    In the end it all came down to the fact that I had to write the method in capital letters POST/GET.

    Hopes that helps.

    • Proposed as answer by Binu Vasudev Sunday, October 12, 2014 3:59 AM
    • Unproposed as answer by Binu Vasudev Sunday, October 12, 2014 4:00 AM
    Monday, December 23, 2013 6:45 PM
  • I don't know if this is the issue but I was also getting a 501 when using MSXML2.ServerXMLHTTP object.

    In the end it all came down to the fact that I had to write the method in capital letters POST/GET.

    Hopes that helps.

    This worked for me too.
    Sunday, October 12, 2014 4:00 AM