Using C # to post XML to a HTTPS service (NON-SOAP) RSS

Source: Internet
Author: User
Tags soap

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 ());

}

}

}

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.