Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- private static XmlDocument sendYoutubeRequest(string requestXml)
- {
- string destinationUrl = "http://gdata.youtube.com/feeds/api/videos/batch";
- HttpWebRequest request = (HttpWebRequest)WebRequest.Create(destinationUrl);
- byte[] bytes;
- bytes = System.Text.Encoding.ASCII.GetBytes(requestXml);
- request.ContentType = "text/xml; encoding='utf-8'";
- request.ContentLength = bytes.Length;
- request.Method = "POST";
- request.Headers.Add("X-GData-Key", "key=(my key)");
- Stream requestStream = request.GetRequestStream();
- requestStream.Write(bytes, 0, bytes.Length);
- requestStream.Close();
- HttpWebResponse response;
- try { response = (HttpWebResponse)request.GetResponse(); }
- catch { return null; }
- if (response.StatusCode == HttpStatusCode.OK)
- {
- Stream responseStream = response.GetResponseStream();
- XmlReader reader = new XmlTextReader(responseStream);
- XmlDocument xmlDoc = new XmlDocument();
- xmlDoc.Load(reader);
- //Close XMLReader
- try { reader.Close(); }
- catch { }
- try { responseStream.Close(); }
- catch { }
- try { response.Close(); }
- catch { }
- return xmlDoc;
- }
- try { response.Close(); }
- catch { }
- return null;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement