Solved

HTTP POST acting like HTTP GET

Posted on 2014-03-05
5
727 Views
Last Modified: 2014-03-06
Hi Experts;
I am attempting to post an XML to a customer's site. It's going to a dedicated URL and has a digital signature in the header.
The HTTP.send command is failing. I'm getting "The download of the specified resource has failed".

The customer informed me that by tacking the XML on to the URL, I'm performing an HTTP.Get instead of HTTP.Post. They want .POST

Here is the customer's example in c# of how he wants it done:

**** start C# example
    HttpWebRequest req = (HttpWebRequest)WebRequest.Create(ConfigurationManager.AppSettings["HttpDestination"].ToString());
            UTF8Encoding encoding = new UTF8Encoding();
            byte[] data = encoding.GetBytes(XMLText);
            req.Method = "POST";
            req.ContentType = "application/x-www-form-urlencoded";
            req.ContentLength = data.Length;
            req.ProtocolVersion = System.Net.HttpVersion.Version10;

            Stream strm = req.GetRequestStream();

            strm.Write(data, 0, data.Length);
            strm.Close();

            HttpWebResponse response = (HttpWebResponse)req.GetResponse();

            response.Close();

Open in new window

**** end C# example

Here is my VB6 code. It already uses .POST - and I don't know how to alter my code to make the .POST not behave like a .GET.

(in the following example strXML = <?xml version="1.0" encoding="utf-8"?><sXml><dataroot><pRec><series_of_elements></series_of_elements></pRec></dataroot></sXml>)


**** Existing VB6 code
        Set objDom = CreateObject("MSXML2.DOMDocument")
        Set objXmlHttp = CreateObject("MSXML2.XMLHTTP")
        
        'digital sig to embed in http header
        Dim sDigSig As String
        Dim objSig As New DigitalSignature.ComClass1
        'objSig.GetSignature returns a SHA1 hash of the private key and message
        sDigSig = objSig.GetSignature(strXML)
        Set objSig = Nothing
        
        objDom.loadXML strXML      
        objDom.async = True 

        strPost = "https://feeds.customer.com/Feed/ & strXML
                        
         objXmlHttp.Open "POST", strPost, False              
         objXmlHttp.setRequestHeader "hash", sDigSig
         objXmlHttp.Send objDom.xml

Open in new window

**** end VB6 code

Any advice is greatly appreciated.
Thanks
klheitz
0
Comment
Question by:klheitz
  • 2
  • 2
5 Comments
 
LVL 5

Accepted Solution

by:
advfinance earned 500 total points
ID: 39906749
I believe your code is POSTing the XML to their web service but also posting it to an address containing the XML (the GET to which they are referring). I think you have an unnecessary MSXML2.DOMDocument (objDOM) and you probably need to amend strPost to not include the value of strXML (you'll know the correct URL better than I).

Try this?

Set objDom = CreateObject("MSXML2.DOMDocument")
Set objXmlHttp = CreateObject("MSXML2.XMLHTTP")
       
'digital sig to embed in http header
Dim sDigSig As String
Dim objSig As New DigitalSignature.ComClass1
'objSig.GetSignature returns a SHA1 hash of the private key and message
sDigSig = objSig.GetSignature(strXML)
Set objSig = Nothing

strPost = "https://feeds.customer.com/Feed/"
                       
objXmlHttp.Open "POST", strPost, False              
objXmlHttp.setRequestHeader "hash", sDigSig
objXmlHttp.Send strXML

Open in new window


--
Chris
0
 

Author Comment

by:klheitz
ID: 39909845
Hi Chris ~
Thank you for the example. I had to change the Send command to 'true' for the mode.

Yesterday, the customer was able to receive the messages - although some were delayed and his proxy logs indicate the delay was from my sending program.

However, this morning  he isn't able to receive any messages. I haven't made any changes and the customer is suggesting my system is 'buffering' before sending.

I've run the following checks - please see the blank header requests and error 12004.
(When I send the same message to a different customer URL, the header requests are not blank and the status = 200 (OK).)

URL: https://feeds.customer.com/Feed
Ready state before POST: 0
Ready state after POST: 1

After .Send command

Response Headers:

Status Text: Unknown
Status: 12004
Ready State after send: 4

Any ideas how I can check for 'buffered data'? or how can I clear my cache?
And do you have any ideas about the above errors?

Thanks again!
0
 
LVL 5

Expert Comment

by:advfinance
ID: 39909954
ERROR_INTERNET_INTERNAL_ERROR

    12004

    An internal error has occurred.

from http://msdn.microsoft.com/en-us/library/windows/desktop/aa385465%28v=vs.85%29.aspx

Now, does that mean an internal error on the remote server (like the HTTP Status 500 we'll all recognise), or an internal error in WinINet?

--
Chris
0
 

Author Closing Comment

by:klheitz
ID: 39910505
Thanks for the help Chris. You solved the POST doing a GET for me :)
I'm still having issues w/ the customer not being able to receive the message and am going to open a new question. They are not getting the header "hash".
Thanks again!
0

Featured Post

IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

Suggested Solutions

You can of course define an array to hold data that is of a particular type like an array of Strings to hold customer names or an array of Doubles to hold customer sales, but what do you do if you want to coordinate that data? This article describes…
Many times as a report developer I've been asked to display normalized data such as three rows with values Jack, Joe, and Bob as a single comma-separated string such as 'Jack, Joe, Bob', and vice versa.  Here's how to do it. 
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…

743 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

15 Experts available now in Live!

Get 1:1 Help Now