Jump to content
Xtreme .Net Talk

Recommended Posts

Posted

Hi I am very new to C# and using VS 2005

 

I need to read some data from database and should post the data in XML format to a Gateway (ASP website). I dont know anything regarding how to Post a XML request to a web page. I have formated the data in XML, but dont know how to move into next step

 

Please advice me what are the steps that I need to take to post a XML request

Posted

I hv done this....

 

THANKS FOR PEOPLE WHO JUST VIEWED AND NOT REPLIED IN THIS SLEEPING FORUM

 

Here is the code:

 

 

private void button2_Click(object sender, EventArgs e)

{

WebRequest myRequest = null;

WebResponse myResponse = null;

 

try

{

string Page;

string outputst;

string fileName = "C:\\Regsitering_Data.xml";

string uri = "https://securee.xxxxxxxxxabc.com/xmlautomation/Upload.aspx";

myRequest = WebRequest.Create(uri);

// Post method

myRequest.Method = "POST";

// content type

myRequest.ContentType = "text/xml";

// Wrap the request stream with a text-based writer

StreamWriter writer = new StreamWriter(myRequest.GetRequestStream());

// Write the xml text into the stream

writer.WriteLine(this.GetTextFromXMLFile(fileName));

writer.Close();

// Send the data to the webserver

myResponse = myRequest.GetResponse();

Stream str = myResponse.GetResponseStream();

StreamReader strReader = new StreamReader(str);

outputst = "";

while ((Page = strReader.ReadLine()) != null)

{

outputst = outputst + Page;

}

}

catch (Exception Ex)

{

MessageBox.Show(Ex.Message.ToString());

}

}

private string GetTextFromXMLFile(string file)

{

StreamReader reader = new StreamReader(file);

string ret = reader.ReadToEnd();

reader.Close();

return ret;

}

}

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...