Solved

How to generate XML request and process response

Posted on 2013-06-10
3
415 Views
Last Modified: 2013-06-29
Hi Experts, can someone show me how I can generate a web request in ASP.NET VB and process the response for the data below. I am not sure how to generate the request and send it to the remote server.

Sample Request (XML)
GET https://sandbox.tchng.com/test_parect/api/v1/gettransaction.xml?productid=21&transactionreference=8421941122&amount=300000 HTTP/1.1
UserAgent: Mozilla/4.0 (compatible; MSIE 6.0; MS Web Services Client Protocol 4.0.30319.239)
Hash: F6FF2E22F99D93DDDA52D71811FD92B3A71FA1968A66216E0D310DAD

Open in new window


Sample Response (XML)
HTTP/1.0 200 OK
Date: Tue, 30 Oct 2012 16:20:56 GMT
Content-Type: application/xml; charset=utf-8
Content-Length: 552
<TransactionQueryResponse xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema"><ResponseCode>00</ResponseCode><ResponseDescription>Approved Successful</ResponseDescription><Amount>300000</Amount><CardNumber>6055</CardNumber><MerchantReference>8421941122</MerchantReference><PaymentReference>ZIB|WEB|VNA|15-10-2012|015933</PaymentReference><RetrievalReferenceNumber>000000538268</RetrievalReferenceNumber><SplitAccounts /><TransactionDate>2012-10-15T11:07:54.547</TransactionDate></TransactionQueryResponse>

Open in new window

0
Comment
Question by:takwirirar
  • 2
3 Comments
 
LVL 16

Expert Comment

by:Easwaran Paramasivam
ID: 39234470
0
 
LVL 1

Accepted Solution

by:
takwirirar earned 0 total points
ID: 39274079
I am sorry that link doesnt seem to have the information I require.

This is what I was looking for

' Create a request for the URL. 
Dim request As WebRequest = _
WebRequest.Create("urlforpage")
' If required by the server, set the credentials.
request.Credentials = CredentialCache.DefaultCredentials
request.Headers.Add("customheader", "headertext")

' Get the response.
Dim response As WebResponse = request.GetResponse()
' Display the status.
Console.WriteLine(CType(response, HttpWebResponse).StatusDescription)
' Get the stream containing content returned by the server.
Dim dataStream As Stream = response.GetResponseStream()
' Open the stream using a StreamReader for easy access.
Dim reader As New StreamReader(dataStream)

'read the XML response
Dim doc As XmlDocument = New XmlDocument()
doc.LoadXml(reader.ReadToEnd())

Dim ResponseCode As XmlElement = doc.DocumentElement("YourElement")
' Retrieve the value from the ResponseCode element.
Dim responseValue As String = YourElement.InnerXml
'Display the values you require
resp.Text = responseValue


' Clean up the streams and the response.
reader.Close()
response.Close()

Open in new window

0
 
LVL 1

Author Closing Comment

by:takwirirar
ID: 39286449
Other Expert comment was not suffient. After looking around I found the answer.
0

Featured Post

Enabling OSINT in Activity Based Intelligence

Activity based intelligence (ABI) requires access to all available sources of data. Recorded Future allows analysts to observe structured data on the open, deep, and dark web.

Join & Write a Comment

Suggested Solutions

In .NET 2.0, Microsoft introduced the Web Site.  This was the default way to create a web Project in Visual Studio 2005.  In Visual Studio 2008, the Web Application has been restored as the default web Project in Visual Studio/.NET 3.x The Web Si…
Browsing the questions asked to the Experts of this forum, you will be amazed to see how many times people are headaching about monster regular expressions (regex) to select that specific part of some HTML or XML file they want to extract. The examp…
Excel styles will make formatting consistent and let you apply and change formatting faster. In this tutorial, you'll learn how to use Excel's built-in styles, how to modify styles, and how to create your own. You'll also learn how to use your custo…
This tutorial demonstrates a quick way of adding group price to multiple Magento products.

707 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

18 Experts available now in Live!

Get 1:1 Help Now