Wrox Programmer Forums
Go Back   Wrox Programmer Forums > ASP.NET and ASP > ASP.NET 3.5 > ASP.NET 3.5 Professionals
|
ASP.NET 3.5 Professionals If you are an experienced ASP.NET programmer, this is the forum for your 3.5 questions. Please also see the Visual Web Developer 2008 forum.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the ASP.NET 3.5 Professionals section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old July 15th, 2009, 02:15 AM
Friend of Wrox
 
Join Date: Oct 2003
Posts: 479
Thanks: 0
Thanked 3 Times in 3 Posts
Send a message via MSN to surendran Send a message via Yahoo to surendran
Default How to post a XML file to a remote server and get a XML response back

i have to post a xml file into a 3rd party server andneed to get the feed abck from them, here is the code I used, but no response code included, please give me a sample

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.IO;
using System.Net;
namespace WebApplication1
{
publicpartialclass_Default : System.Web.UI.Page
{
protectedvoid abc()
{
WebRequest req = null;
WebResponse rsp = null;
try
{
string fileName = "C:/test.txt";
string uri = "https://www.ntorder-dev.com/ocs-nisa/B2B/";
req = WebRequest.Create(uri);
//req.Proxy = WebProxy.GetDefaultProxy(); // Enable if using proxy
req.Method = "POST"; // Post method
req.ContentType = "text/xml"; // content type
// Wrap the request stream with a text-based writer
StreamWriter writer = newStreamWriter(req.GetRequestStream());
// Write the XML text into the stream
writer.WriteLine(this.GetTextFromXMLFile(fileName));
writer.Close();
// Send the data to the webserver
rsp = req.GetResponse();
}
catch (WebException webEx)
{
}
catch (Exception ex)
{
}
finally
{
if (req != null) req.GetRequestStream().Close();
if (rsp != null) rsp.GetResponseStream().Close();
}
}
protectedvoid Page_Load(object sender, EventArgs e)
{
abc();
this.Response.ContentType = "text/xml";
// Read XML posted via HTTP
StreamReader reader = newStreamReader(this.Request.InputStream);
String xmlData = reader.ReadToEnd();
}
privatestring GetTextFromXMLFile(string file)
{
StreamReader reader = newStreamReader(file);
string ret = reader.ReadToEnd();
reader.Close();
return ret;
}
}
}
__________________
surendran
(Anything is Possible)
http://www.suren.info
http://ssuren.spaces.msn.com
 
Old July 15th, 2009, 03:22 AM
Registered User
 
Join Date: Jul 2009
Posts: 1
Thanks: 1
Thanked 0 Times in 0 Posts
Default The transport failed to connect to the server.

Dim myMail
Set myMail=CreateObject("CDO.Message")
myMail.Subject = strSubject
myMail.From= strFrom
myMail.To= strTo
' myMail.TextBody= strBody
myMail.HTMLBody= strBody
myMail.Configuration.Fields.Item _
("http://schemas.microsoft.com/cdo/configuration/sendusing")=2
'Name or IP of remote SMTP server
myMail.Configuration.Fields.Item _
("http://schemas.microsoft.com/cdo/configuration/smtpserver") _
="k2smtpout.secureserver.net"
'Server port
myMail.Configuration.Fields.Item _
("http://schemas.microsoft.com/cdo/configuration/smtpserverport") _
=25
myMail.Configuration.Fields.Update
myMail.Send
set myMail=nothing
 
Old January 29th, 2010, 03:39 AM
Registered User
 
Join Date: Jan 2010
Posts: 1
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Quote:
Originally Posted by surendran View Post
i have to post a xml file into a 3rd party server andneed to get the feed abck from them, here is the code I used, but no response code included, please give me a sample

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.IO;
using System.Net;
namespace WebApplication1
{
publicpartialclass_Default : System.Web.UI.Page
{
protectedvoid abc()
{
WebRequest req = null;
WebResponse rsp = null;
try
{
string fileName = "C:/test.txt";
string uri = "https://www.ntorder-dev.com/ocs-nisa/B2B/";
req = WebRequest.Create(uri);
//req.Proxy = WebProxy.GetDefaultProxy(); // Enable if using proxy
req.Method = "POST"; // Post method
req.ContentType = "text/xml"; // content type
// Wrap the request stream with a text-based writer
StreamWriter writer = newStreamWriter(req.GetRequestStream());
// Write the XML text into the stream
writer.WriteLine(this.GetTextFromXMLFile(fileName));
writer.Close();
// Send the data to the webserver
rsp = req.GetResponse();
}
catch (WebException webEx)
{
}
catch (Exception ex)
{
}
finally
{
if (req != null) req.GetRequestStream().Close();
if (rsp != null) rsp.GetResponseStream().Close();
}
}
protectedvoid Page_Load(object sender, EventArgs e)
{
abc();
this.Response.ContentType = "text/xml";
// Read XML posted via HTTP
StreamReader reader = newStreamReader(this.Request.InputStream);
String xmlData = reader.ReadToEnd();
}
privatestring GetTextFromXMLFile(string file)
{
StreamReader reader = newStreamReader(file);
string ret = reader.ReadToEnd();
reader.Close();
return ret;
}
}
}
HttpWebRequest request = (HttpWebRequest)WebRequest.Create("http://xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx.com");
request.KeepAlive = false;
HttpWebResponse response = (HttpWebResponse)request.GetResponse();

Stream receiveStream = response.GetResponseStream();
Encoding encode = System.Text.Encoding.GetEncoding("utf-8");

// Pipes the stream to a higher level stream reader with the required encoding format.
StreamReader readStream = new StreamReader(receiveStream, encode);

while (!readStream.EndOfStream)
{
Debug.WriteLine(readStream.ReadLine());
}

readStream.Close();



response.Close();





Similar Threads
Thread Thread Starter Forum Replies Last Post
C# post xml using HttpWebRequest/Response datakix ASP.NET 1.0 and 1.1 Professional 6 June 14th, 2016 07:47 AM
Post a xml file to an URL? chengjianjin XML 10 June 10th, 2010 02:05 AM
how to post xml data to server and reading back js_pandey PHP How-To 0 March 29th, 2006 01:48 PM
Request and Response from server in XML snarreddi XML 3 December 24th, 2004 07:20 AM
Help sending XML file to server, reading response bradartigue XML 1 September 5th, 2003 07:42 AM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.