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();
|