Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- private static async Task Post()
- {
- HttpWebRequest request = (HttpWebRequest) WebRequest.Create("http://localhost:5000/setxml");
- try
- {
- request.Method = "POST";
- var data = System.Text.Encoding.UTF8.GetBytes("xml="+File.ReadAllText("file1.xml"));
- request.ContentType = "application/x-www-form-urlencoded";
- request.ContentLength = data.Length;
- using (Stream dataStream = request.GetRequestStream())
- {
- dataStream.Write(data, 0, data.Length);
- }
- var response = (HttpWebResponse) await request.GetResponseAsync();
- using (Stream stream = response.GetResponseStream())
- {
- using (StreamReader reader = new StreamReader(stream))
- {
- string line = "";
- while ((line = reader.ReadLine()) != null)
- {
- Console.WriteLine(line);
- }
- }
- }
- response.Close();
- }
- catch (Exception e)
- {
- Console.WriteLine(e);
- }
- Console.WriteLine("Запрос выполнен");
- Console.Read();
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement