Using System;
Using System.Collections;
Using System.Configuration;
Using System.Data;
Using System.Linq;
Using System.Web;
Using System.Web.Security;
Using System.Web.UI;
Using System.Web.UI.HtmlControls;
Using System.Web.UI.WebControls;
Using System.Web.UI.WebControls.WebParts;
Using System.Xml.Linq;
Using System.Net;
Using System.Xml;
Using System.Text;
Using System.IO;
public partial class PostXml:System.Web.UI.Page
{
protected void Page_Load (object sender, EventArgs e)
{
}
protected void Button1_Click (object sender, EventArgs e)
{
Try
{
HttpWebResponse resp;
String TargetUrl;
TargetUrl = "Https://stg1-ss1.experian.com/netconnect2_0Demo/servlets/NetConnectServlet";
HttpWebRequest request = (HttpWebRequest) webrequest.create (TargetUrl);
Response.Write ("Connecting to URL:" + targeturl + "<br>");
Read input XML from file
StringBuilder sb = new StringBuilder ();
String Inputxml;
using (StreamReader Inputqueryreader = new StreamReader ("C:\\1.xml"))
{
Sb. Append (Inputqueryreader.readtoend ());
}
Response.Write ("Input XML value:" + sb.) ToString () + "<br>");
Encode post data and set up the request Note:input XML is passed a a parameter named Netconnect_transaction '
Sb. Append ("&netconnect_transaction=" + sb.) ToString ());
String postdata = sb. ToString ();
Response.Write ("PostData:" + postdata);
byte[] Authbytes = Encoding.ASCII.GetBytes ("Aa:aa");
String Sauth = Convert.tobase64string (authbytes);
Request. Headers.add ("Authorization", "Basic" + Sauth);
NetworkCredential cred = new NetworkCredential ("AA", "AA");
byte[] postdatabytes = Encoding.UTF8.GetBytes (postdata);
Request. Credentials = cred;
Request. method = "POST";
Request. ContentType = "application/x-www-form-urlencoded";
Request. ContentLength = Postdatabytes.length;
Stream requeststream = Request. GetRequestStream ();
requestStream.Write (postdatabytes, 0, postdatabytes.length);
Requeststream.close ();
Get response and write to console
RESP = (httpwebresponse) request. GetResponse (); THROWS an EXCEPTION
Response.Write ("Got a Response from the Target URL, response:<br>");
StreamReader Responsereader = new StreamReader (resp. GetResponseStream (), Encoding.UTF8);
Response.Write (Responsereader.readtoend ());
Resp. Close ();
}
catch (Exception ex)
{
Response.Write (ex. ToString ());
}
}
}