473,802 Members | 1,996 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

C#: Http post

2 New Member
Dear all,

This is my first post in this forum.

I am writing a small module for my company that send XML data to a gateway (Asp page) and get the response in XML format

I have to send the data (request) in XML format to a web site and need to get the response for the request
First I tried with Webclient (System.Net.Web Client) with following codes


Expand|Select|Wrap|Line Numbers
  1. Client.UploadFile("http://sample_site/upload.aspx", @"C://Regsitering_Data.xml");
  2. Client.DownloadFile("http://sample_site/downloaddata.aspx","C:\\Responses.asp")
  3.  
  4.  
However, this way I managed to post the data. I checked with the gateway people and they confirmed that my request is correct and the webservice has sent the response correctly. However I am not able to get the response from there.

I know that I am doing wrong. I tried with HttpWebRequest and HttpWebResponse , but I dont know how to post XML data into the with using
HttpWebRequest

Please help me on this. Is there any way that I can send a request to website along with XML data
Mar 19 '08 #1
3 1965
Plater
7,872 Recognized Expert Expert
You have to do a bit more work (I think) with HttpWebRequest.
MSDN has an example about posting data.
You would create it, set the method type to POST, then you would need to read in the XML data into a string (I think), tell the HttpWebRequest the length of the string and then use the request stream to dump the XML data into it.
Mar 19 '08 #2
rajeeshun
2 New Member
I have done the work. Got some samples thescripts and other sites

Thanks to all

Expand|Select|Wrap|Line Numbers
  1.  private void button2_Click(object sender, EventArgs e)
  2.         {
  3.             WebRequest myRequest = null;
  4.             WebResponse myResponse = null;
  5.  
  6.             try
  7.             {
  8.                 string Page;
  9.                 string outputst;
  10.                 string fileName = "C:\\Regsitering_Data.xml";
  11.                 string uri = "https://secure.abcdef.com/xmlautomation/Upload.aspx";
  12.                 myRequest = WebRequest.Create(uri);
  13.                 // Post method
  14.                 myRequest.Method = "POST";
  15.                 // content type
  16.                 myRequest.ContentType = "text/xml"; 
  17.                 // Wrap the request stream with a text-based writer
  18.                 StreamWriter writer = new StreamWriter(myRequest.GetRequestStream());
  19.                 // Write the xml text into the stream
  20.                 writer.WriteLine(this.GetTextFromXMLFile(fileName));
  21.                 writer.Close();
  22.                 // Send the data to the webserver
  23.                 myResponse = myRequest.GetResponse();
  24.                 Stream str = myResponse.GetResponseStream();
  25.                 StreamReader strReader = new StreamReader(str);
  26.                 outputst = "";
  27.                 while ((Page = strReader.ReadLine()) != null)
  28.                 {
  29.                     outputst = outputst + Page;
  30.                 }
  31.             }
  32.             catch (Exception Ex)
  33.             {
  34.                 MessageBox.Show(Ex.Message.ToString());
  35.             }
  36.         }
  37. private string GetTextFromXMLFile(string file)
  38.         {
  39.             StreamReader reader = new StreamReader(file);
  40.             string ret = reader.ReadToEnd();
  41.             reader.Close();
  42.             return ret;
  43.         }
Mar 19 '08 #3
Plater
7,872 Recognized Expert Expert
If you need more controll the
WebRequest and WebResponse
Can be explicitly cast as
HttpWebRequest and HttpWebResponse
Mar 19 '08 #4

Sign in to post your reply or Sign up for a free account.

Similar topics

4
17134
by: Gary Petersen | last post by:
For the benefit of others, I want to show how to do an HTTP POST request using fsockopen(). I banged my head against a wall for two days trying to figure this out. I even went to http://php.net/ to find out how to do this, but it didn't help because my mind automagically converted the "Content-Length" header into "Length." I even went to http://www.ietf.org/ to find out the specific protocol for HTTP POSTs, but I didn't
0
2467
by: Spud | last post by:
<?php // pullpage function by Nick bouton http://www.nickbouton.com/. $CustomerID = "IDHERE"; $method = "POST"; $host = "xml.mydata.com"; $usepath = "/xml.asp"; //print all vars in an array
7
2617
by: Dodger | last post by:
Apologies if the is the wrong NG. But I have trapped a GET issued by a webpage on a button press and I would like to issue the GET programatically as-and-when I wish. I wondered what the text before the get text signifies? I imagine they are variable names and parameter values. Is this correct?
0
1833
by: Owen | last post by:
Hello everyone, I am using VS.NET 2003(Trandition Chinese) Edition, and httpLook software for checking http requests. I found a problem that the following programs don't really "POST". These programs can be successfully compiled. There is no error message shown at running also. But the httpLook confirms that the program doesn't post. -- Here is the HTTP request acquired by the software: ---
0
3889
by: WIWA | last post by:
Hi, I want to login to a password protected website and fetch the content of the page behind. I have based my code on http://weblogs.asp.net/jdennany/archive/2005/04/23/403971.aspx. When I use tools like ieHTTPHeaders v1.6, and I perform a normal login (using the normal website), I see that the viewstate is __VIEWSTATE=dDwxMzU4OTE3NTA2Ozs%2BTK88jS63JXN181X3N8zKivua8co%3D&txt_username=xxx&txt_password=xxxxxx&btn_login=Login. When I...
5
10403
by: David Lozzi | last post by:
Howdy, I wrote a web service in .Net for my customer. My customer has another vendor who now has to consume it but they are not using Visual Studio. Most of their pages are jsp, and they said they need to consume this web service using HTTP. The developer's IDE is Notepad. Yeah, weird I know. How is this done? I guess if I can get it to run ASP, IDE independant, that should make them happy. Any references you can point me to?
3
4932
by: JansenH | last post by:
We have implemented a 'HTTP Post' client in C# that posts Xml documents to a webserver. This is working fine if the post rate is one post for every 20 seconds. But if the post rate is increased to one post for every 10 seconds the client start getting error 403 'forbidden' from the webserver after a short period of time. The webserver is IIS. The choking of the client/server communication when doing high frequency posting is due to that we...
1
2608
by: Arfeen | last post by:
Hi All, I need help again ..... I have an asp.net web page which I hit using the "HTTP POST" method. My ASP.NET page is a basic hello world example with the following code: private void Page_Load(object sender, System.EventArgs e) {
2
5442
by: =?Utf-8?B?cGhlbmdsYWk=?= | last post by:
I am not sure really how to explain this but here goes. I am creating some new web services and I want to be able to post data like the following: <Data> <some value>1</some value> <more info>2</more info> </Data>
6
5109
by: Brybot | last post by:
I am trying to allow HTTP POST file uploads to my web service. Currently I have it working perfectly for a SOAP/XML request reading in a byte using MemoryStream/FileStream but I cannot figure out how to encode a file on a POST to the same web service. The definition requires a base64binary encoded file, which I have tried. The form is also using a mutlipart/form-data enctype, but I either get a 500 error or 'Request format is invalid'. ...
0
9699
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9562
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
1
10285
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
10063
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
9114
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7598
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5494
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
1
4270
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
3
2966
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.