Advertisement
Guest User

Untitled

a guest
Jul 9th, 2013
4,287
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.29 KB | None | 0 0
  1. private static XmlDocument sendYoutubeRequest(string requestXml)
  2. {
  3.     string destinationUrl = "http://gdata.youtube.com/feeds/api/videos/batch";
  4.    
  5.     HttpWebRequest request = (HttpWebRequest)WebRequest.Create(destinationUrl);
  6.     byte[] bytes;
  7.     bytes = System.Text.Encoding.ASCII.GetBytes(requestXml);
  8.     request.ContentType = "text/xml; encoding='utf-8'";
  9.     request.ContentLength = bytes.Length;
  10.     request.Method = "POST";
  11.     request.Headers.Add("X-GData-Key", "key=(my key)");
  12.     Stream requestStream = request.GetRequestStream();
  13.     requestStream.Write(bytes, 0, bytes.Length);
  14.     requestStream.Close();
  15.     HttpWebResponse response;
  16.     try { response = (HttpWebResponse)request.GetResponse(); }
  17.     catch { return null; }
  18.     if (response.StatusCode == HttpStatusCode.OK)
  19.     {
  20.         Stream responseStream = response.GetResponseStream();
  21.         XmlReader reader = new XmlTextReader(responseStream);
  22.  
  23.         XmlDocument xmlDoc = new XmlDocument();
  24.         xmlDoc.Load(reader);
  25.  
  26.         //Close XMLReader
  27.         try { reader.Close(); }
  28.         catch { }
  29.         try { responseStream.Close(); }
  30.         catch { }
  31.         try { response.Close(); }
  32.         catch { }
  33.         return xmlDoc;
  34.     }
  35.     try { response.Close(); }
  36.     catch { }
  37.     return null;
  38. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement