dotnet-Snippets.com
Snippets: 76 | Registered User: 92 | Visitors online: 4
Main Menu

Home
Random Snippet
FAQs
Contact Us
Imprint
RSS Feeds

Rss All languages
Rss C#
Rss VB.NET
Rss C++
Rss J#
Rss ASP.NET
Jobs

dotnet Jobs
Google Ads

Sri Lanka .NET 
                Forum Member
Simple Web-Request with Web-Response

Author: Linoge
Programming Language: C# Rating:
not yet rated

Views: 3342

Description:

Sample to build a simple Web-Request with a simple Server-Web-Response interpretation



C#
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
//Create a Web-Request to an URL
HttpWebRequest HWR_Request = (HttpWebRequest)WebRequest.Create("www.yourURL.com");

//Defined poperties for the Web-Request
HWR_Request.Method = "POST";
HWR_Request.MediaType = "HTTP/1.1";
HWR_Request.ContentType = "text/xml";
HWR_Request.UserAgent = "SNIP_CLIENT/1.0";

//Defined data for the Web-Request
byte[] b_Data = Encoding.ASCII.GetBytes("A string you would like to send");
HWR_Request.ContentLength = b_Data.Length;

//Attach data to the Web-Request
Stream S_DataStream = HWR_Request.GetRequestStream();
S_DataStream.Write(b_Data, 0, b_Data.Length);
S_DataStream.Close();

//Send Web-Request and receive a Web-Response
HttpWebResponse HWR_Response = (HttpWebResponse)HWR_Request.GetResponse();

//Translate data from the Web-Response to a string
S_DataStream = HWR_Response.GetResponseStream();
StreamReader SR_DataStream = new StreamReader(S_DataStream, Encoding.UTF8);
string s_ResponseString = SR_DataStream.ReadToEnd();
SR_DatenStream.Close();
S_DatenStream.Close();

This Snippets could be interesting for you:

Poor Excellent
1 2 3 4 5 6 7 8 9 10
Sign in to vote for this snippet.

Comments:
(Please log in to write an comment.)