Solved

How to submit HTTPS POSTs to external address and get response in XML

Posted on 2011-03-22
5
575 Views
Last Modified: 2012-05-11
Hi Experts,

I'm trying to do an integration with the SagePay Reporting and Admin API but the documentation is pretty thin shall we say!

It 'sounds' like it should be easy but I've not done this before so any help much appreciated.  Basically the guide states:

"The API requests are HTTPS POSTs to the URLs above, containing a single FORM field called XML. It is important to note that these are not requests in XML format, but regular HTTPS POSTs with the content type “application/x-www-form-urlencoded” with the XML requests detailed below in a FORM field called XML.

The XML field will contain the XML message, which always takes the following format:
<vspaccess>
<command>whatever</command>
<vendor>Vendor Name</vendor>
<user>User name</user>
<other command specific parameters in here..../>
<signature>MD5 Hash Signature</signature>
</vspaccess>

The <signature> value is created by taking the rest of the contents of the <vspaccess> node, appending an element called <password> which contains the user account's password, and MD5 hashing the message. So in the above example:
MD5 Hash Signature =
MD5Hash(
"<command>whatever</command>
<vendor>VSP Vendor Name</vendor>
<user>User name</user>
<other command specific params in here..../>
<password>user password</password>")
The response format will always be a XML v1.0 ISO-8859-1 encoded document with a root node called <vspaccess>. i.e.:
<?xml version="1.0" encoding="ISO-8859-1" ?>
<vspaccess>
<errorcode>nnnn</errorcode>
<error>Text error message if errorocode is not 0000</error>
<other command specific results here..../>
<timestamp>DD/MM/YY HH:MM:SS GMT</timestamp>
</vspaccess>

And that is all we get!  If someone more enlightened than me could please explain how I use this to create a form in ASP.NET 2.0 (i.e. can't use LINQ), to query the SagePay interface and how to then interpret the result, it would be much appreciated.  

Classic ASP may also be a useful solution.

Regards,

Jay
0
Comment
Question by:jammy-d0dger
[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
5 Comments
 
LVL 11

Accepted Solution

by:
G_H earned 500 total points
ID: 35194748
Hi Jay,

Classic ASP version...

 
<%
strPost =  _
	"VariableA=" & VariableAValue & _
	"&VariableB=" & VariableBValue

set httpRequest = CreateObject("WinHttp.WinHttprequest.5.1")
	httpRequest.Open "POST", CStr(strURL), false
	httpRequest.setRequestHeader "Content-Type", "application/x-www-form-urlencoded"
	httpRequest.send strPost
	strResponse = httpRequest.responseText
set httpRequest=nothing
%>

Open in new window


This generates a "posted form" to SagePay, you the get the response back, which you will have to deal with...

Hope this helps,

GH
0
 
LVL 11

Assisted Solution

by:G_H
G_H earned 500 total points
ID: 35194777
Sorry, forgot to say...

The example shows 2 variables sent, even though you asked for 1 (just to show how it works).
You will need to populate strURL with the target they want you to use.
strResponse will be the entire XML returned to you, you will need to process-out what you want (That I guess you can handle!).

See also, two attached lines which may help...

XMLValue = _
	"<vspaccess>" & _
	"<command>whatever</command>" & _
	"<vendor>Vendor Name</vendor>" & _
	"<user>User name</user>" & _
	"<other command specific parameters in here..../>" & _
	"<signature>MD5 Hash Signature</signature>" & _
	"</vspaccess>"
	
strPost = "XML=" & XMLValue

Open in new window


GH

0
 

Author Comment

by:jammy-d0dger
ID: 35209838
Nice one, much appreciated.  I will give this a go tomorrow when back in the office, and let you know.
0
 
LVL 143

Expert Comment

by:Guy Hengel [angelIII / a3]
ID: 35877207
This question has been classified as abandoned and is closed as part of the Cleanup Program. See the recommendation for more details.
0

Featured Post

Salesforce Has Never Been Easier

Improve and reinforce salesforce training & adoption using WalkMe's digital adoption platform. Start saving on costly employee training by creating fast intuitive Walk-Thrus for Salesforce. Claim your Free Account Now

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
ASP exit 10 28
Validating textboxes in red square borders. 2 35
Set the FileVersion of a website dll 1 31
SP converting date time to date and time separately 2 20
I would like to start this tip/trick by saying Thank You, to all who said that this could not be done, as it forced me to make sure that it could be accomplished. :) To start, I want to make sure everyone understands the importance of utilizing p…
ASP.Net to Oracle Connectivity Recently I had to develop an ASP.NET application connecting to an Oracle database.As I am doing it first time ,I had to solve several problems. This article will help to such developers  to develop an ASP.NET client…
Although Jacob Bernoulli (1654-1705) has been credited as the creator of "Binomial Distribution Table", Gottfried Leibniz (1646-1716) did his dissertation on the subject in 1666; Leibniz you may recall is the co-inventor of "Calculus" and beat Isaac…

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