Click here to Skip to main content
15,892,298 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi all,
I writing a project the requires me to consume an api. i add a we reference to my asp.net application and tried to initiate a request but the response i got were empty strings for some fields. so, i decided to use Xdocument in xml to pass the request also i got an empty string.

below is the code line i use in c#
 protected void Page_Load(object sender, EventArgs e)
    {
        // load that XML that you want to post
// it doesn't have to load from an XML doc, this is just
// how we do it
XmlDocument doc = new XmlDocument();
doc.Load( Server.MapPath( "XMLFile2.xml" ) );


// create the request to your URL
HttpWebRequest request = (HttpWebRequest)WebRequest.Create("http://localhost:2092/newlocaidstuff/Default4.aspx");

// add the headers
// the SOAPACtion determines what action the web service should use
// YOU MUST KNOW THIS and SET IT HERE
//request.Headers.Add( "SOAPAction", YOUR SOAP ACTION );

// set the request type
// we user utf-8 but set the content type here
request.ContentType = "text/xml;charset=\"utf-8\"";
request.Accept = "text/xml";
request.Method = "POST";

// add our body to the request
System.IO.Stream stream = request.GetRequestStream();
doc.Save( stream );
stream.Close();

// get the response back
using( HttpWebResponse response = (HttpWebResponse)request.GetResponse() )
{

    System.IO.StreamReader rd = new System.IO.StreamReader(response.GetResponseStream());
// do something with the response here
    Response.Write(rd);
    

}//end using
    }
Posted
Updated 16-Aug-13 8:33am
v2

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900