Solved

HTTP POST acting like HTTP GET

Posted on 2014-03-05
5
775 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
[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: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

Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

Question has a verified solution.

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

The debugging module of the VB 6 IDE can be accessed by way of the Debug menu item. That menu item can normally be found in the IDE's main menu line as shown in this picture.   There is also a companion Debug Toolbar that looks like the followin…
I was working on a PowerPoint add-in the other day and a client asked me "can you implement a feature which processes a chart when it's pasted into a slide from another deck?". It got me wondering how to hook into built-in ribbon events in Office.
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…
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…

730 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