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
Solved

How to generate XML request and process response

Posted on 2013-06-10
3
419 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

Master Your Team's Linux and Cloud Stack!

The average business loses $13.5M per year to ineffective training (per 1,000 employees). Keep ahead of the competition and combine in-person quality with online cost and flexibility by training with Linux Academy.

Question has a verified solution.

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

The Client Need Led Us to RSS I recently had an investment company ask me how they might notify their constituents about their newsworthy publications.  Probably you would think "Facebook" or "Twitter" but this is an interesting client.  Their cons…
User art_snob (http://www.experts-exchange.com/M_6114203.html) encountered strange behavior of Android Web browser on his Mobile Web site. It took a while to find the true cause. It happens so, that the Android Web browser (at least up to OS ver. 2.…
Email security requires an ever evolving service that stays up to date with counter-evolving threats. The Email Laundry perform Research and Development to ensure their email security service evolves faster than cyber criminals. We apply our Threat…

809 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