Wrox Programmer Forums

Need to download code?

View our list of code downloads.

Go Back   Wrox Programmer Forums > ASP.NET and ASP > ASP.NET 3.5 > ASP.NET 3.5 Professionals
Password Reminder
Register
| FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read
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 tens of thousands of software programmers and website developers including Wrox book authors and readers. As a guest, you can read any forum posting. By joining today you can post your own programming questions, respond to other developers’ questions, and eliminate the ads that are displayed to guests. Registration is fast, simple and absolutely free .
DRM-free e-books 300x50
 
 
Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old July 15th, 2009, 02:15 AM
Friend of Wrox
 
Join Date: Oct 2003
Location: colombo, WP, Sri Lanka.
Posts: 481
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
  #2 (permalink)  
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
  #3 (permalink)  
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();
 


Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are Off


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



All times are GMT -4. The time now is 03:05 PM.


Powered by vBulletin®
Copyright ©2000 - 2019, Jelsoft Enterprises Ltd.
© 2013 John Wiley & Sons, Inc.