Solved

HTTP POST acting like HTTP GET

Posted on 2014-03-05
5
803 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:k heiutz
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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:k heiutz
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:k heiutz
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

Learn by Doing. Anytime. Anywhere.

Do you like to learn by doing?
Our labs and exercises give you the chance to do just that: Learn by performing actions on real environments.

Hands-on, scenario-based labs give you experience on real environments provided by us so you don't have to worry about breaking anything.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

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…
Since upgrading to Office 2013 or higher installing the Smart Indenter addin will fail. This article will explain how to install it so it will work regardless of the Office version installed.
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…

696 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