Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- private void HandleRequest(string url, string method = "GET", string data = null)
- {
- HttpWebRequest req = WebRequest.Create(new Uri(url)) as HttpWebRequest;
- req.Method = method.ToUpper();
- req.Accept = "application/xml";
- req.ContentType = "application/xml";
- req.AllowAutoRedirect = true;
- string authInfo = Convert.ToBase64String(Encoding.GetEncoding(1252).GetBytes("yourapi:keyhere"));
- req.Headers.Add(HttpRequestHeader.Authorization, string.Format("Basic {0}", authInfo));
- if (! string.IsNullOrEmpty(data))
- {
- byte[] rawBytes = Encoding.GetEncoding(1252).GetBytes(data);
- req.ContentLength = rawBytes.Length;
- using (Stream reqStream = req.GetRequestStream())
- {
- reqStream.Write(rawBytes, 0, rawBytes.Length);
- }
- }
- using (HttpWebResponse resp = req.GetResponse() as HttpWebResponse)
- {
- using (StreamReader reader = new StreamReader(resp.GetResponseStream()))
- {
- Console.WriteLine(reader.ReadToEnd());
- }
- }
- }
Add Comment
Please, Sign In to add comment