R
ratnakarp
Hi,
I'm new to httpwebrequest programming. I'm using httpwebrequest to
pull the rss file with contenttype as "GET". it works fine. I get all
the results and store all the values in the list. the list has a url
(desclink) property too. i do httpwebrequest again for these url's
with contenttype as "POST". some how i dont understand the problem,
but my page hangs and doesnt retreive any value. i'm pasting the code
below, any help would be appreciated.
Default.aspx
---------------------
XmlParse test1 = new XmlParse();// see the code below for
xmlparse.cs
List<XmlTags> tags1 = new List<XmlTags>();
// System.Net.WebProxy objProxy = new
System.Net.WebProxy("http://usushproxy01:80");
tags1= test1.GetXmlInfo("<rss file"> );
HttpWebRequest objRequest;
for (int i = 1; i < tags1.Count; i++)
{
// Response.Write(tags1.Description + "<br>");
string strPost = "Hello";
//System.Net.WebProxy objProxy1 = new
System.Net.WebProxy("http://usushproxy01:80");
objRequest =
(HttpWebRequest)WebRequest.Create(tags1.DescLink );
//objRequest.Proxy = objProxy;
objRequest.Method = "POST";
objRequest.ContentType = "application/x-www-form-
urlencoded";
objRequest.ContentLength = strPost.Length;
//objRequest.Timeout = 1000000;
//objRequest.KeepAlive = false;
StreamWriter myWriter = new
StreamWriter(objRequest.GetRequestStream());
myWriter.Flush();
myWriter.Write(strPost);
myWriter.Close();
objRequest.GetRequestStream().Close();
string strHold;
//HtmlMetaParser.
objRequest.GetRequestStream().Close();
HttpWebResponse objResponse =
(HttpWebResponse)objRequest.GetResponse();
using (StreamReader sr = new
StreamReader(objResponse.GetResponseStream()))
{
// sr something
strHold = sr.ReadToEnd().ToString();
List<HtmlMeta> Meta1 = HtmlMetaParser.Parse(strHold);
string strmeta="";
for (int j = 0; j < Meta1.Count; j++)
{
strmeta = Meta1[j].Content.ToString();
}
Response.Write(strmeta + "<br><br><br><br><hr/>");
sr.Close();
}
objRequest.Abort();
}
XmlParse.cs
--------------------------
public class XmlParse
{
public XmlParse()
{
//
// TODO: Add constructor logic here
//
}
public List<XmlTags> GetXmlInfo(string uri)
{
List<XmlTags> myList = new List<XmlTags>();
HttpWebRequest objRequest =
(HttpWebRequest)WebRequest.Create("http://nbcumv.com/feeds/
bravo.en.xml");
string strPost = "Hello";
//objRequest.Proxy = objProxy;
objRequest.Method = "GET";
objRequest.ContentType = "application/x-www-form-urlencoded";
objRequest.ContentLength = strPost.Length;
//objRequest.Timeout = 1000000;
//objRequest.KeepAlive = false;
HttpWebResponse objResponse =
(HttpWebResponse)objRequest.GetResponse();
string str;
string strHold;
using (StreamReader sr = new
StreamReader(objResponse.GetResponseStream()))
{
strHold = sr.ReadToEnd().ToString();
sr.Close();
}
objRequest.Abort();
XmlDocument doc = new XmlDocument();
doc.LoadXml(strHold );
XmlNodeList nodelist = doc.GetElementsByTagName("item");
for (int i = 0; i < nodelist.Count; i++)
{
XmlTags XmlTags1 = new XmlTags();
XmlTags1.Title = nodelist.Item(i).ChildNodes[0].InnerText;
XmlTags1.Link = nodelist.Item(i).ChildNodes[1].InnerText;
XmlTags1.Description =
nodelist.Item(i).ChildNodes[2].InnerText;
string strtest =
XmlTags1.Description.Substring(XmlTags1.Description.IndexOf("</a>"));
XmlTags1.Description = strtest.Replace("</a>","");
string str2 = nodelist.Item(i).ChildNodes[2].InnerText;
XmlTags1.DescLink =
nodelist.Item(i).ChildNodes[2].InnerText.Substring(9,
nodelist.Item(i).ChildNodes[2].InnerText.IndexOf("><img src=")-10);
XmlTags1.ImageLink =
nodelist.Item(i).ChildNodes[2].InnerText.Substring(nodelist.Item(i).ChildNodes[2].InnerText.IndexOf("><img
src=") + 11, str2.LastIndexOf("rss=1") -
nodelist.Item(i).ChildNodes[2].InnerText.IndexOf("><img src=") - 6);
XmlTags1.Author =
nodelist.Item(i).ChildNodes[3].InnerText;
XmlTags1.Date = nodelist.Item(i).ChildNodes[4].InnerText;
myList.Add(XmlTags1);
}
objResponse.Close();
return myList;
}
}
I'm new to httpwebrequest programming. I'm using httpwebrequest to
pull the rss file with contenttype as "GET". it works fine. I get all
the results and store all the values in the list. the list has a url
(desclink) property too. i do httpwebrequest again for these url's
with contenttype as "POST". some how i dont understand the problem,
but my page hangs and doesnt retreive any value. i'm pasting the code
below, any help would be appreciated.
Default.aspx
---------------------
XmlParse test1 = new XmlParse();// see the code below for
xmlparse.cs
List<XmlTags> tags1 = new List<XmlTags>();
// System.Net.WebProxy objProxy = new
System.Net.WebProxy("http://usushproxy01:80");
tags1= test1.GetXmlInfo("<rss file"> );
HttpWebRequest objRequest;
for (int i = 1; i < tags1.Count; i++)
{
// Response.Write(tags1.Description + "<br>");
string strPost = "Hello";
//System.Net.WebProxy objProxy1 = new
System.Net.WebProxy("http://usushproxy01:80");
objRequest =
(HttpWebRequest)WebRequest.Create(tags1.DescLink );
//objRequest.Proxy = objProxy;
objRequest.Method = "POST";
objRequest.ContentType = "application/x-www-form-
urlencoded";
objRequest.ContentLength = strPost.Length;
//objRequest.Timeout = 1000000;
//objRequest.KeepAlive = false;
StreamWriter myWriter = new
StreamWriter(objRequest.GetRequestStream());
myWriter.Flush();
myWriter.Write(strPost);
myWriter.Close();
objRequest.GetRequestStream().Close();
string strHold;
//HtmlMetaParser.
objRequest.GetRequestStream().Close();
HttpWebResponse objResponse =
(HttpWebResponse)objRequest.GetResponse();
using (StreamReader sr = new
StreamReader(objResponse.GetResponseStream()))
{
// sr something
strHold = sr.ReadToEnd().ToString();
List<HtmlMeta> Meta1 = HtmlMetaParser.Parse(strHold);
string strmeta="";
for (int j = 0; j < Meta1.Count; j++)
{
strmeta = Meta1[j].Content.ToString();
}
Response.Write(strmeta + "<br><br><br><br><hr/>");
sr.Close();
}
objRequest.Abort();
}
XmlParse.cs
--------------------------
public class XmlParse
{
public XmlParse()
{
//
// TODO: Add constructor logic here
//
}
public List<XmlTags> GetXmlInfo(string uri)
{
List<XmlTags> myList = new List<XmlTags>();
HttpWebRequest objRequest =
(HttpWebRequest)WebRequest.Create("http://nbcumv.com/feeds/
bravo.en.xml");
string strPost = "Hello";
//objRequest.Proxy = objProxy;
objRequest.Method = "GET";
objRequest.ContentType = "application/x-www-form-urlencoded";
objRequest.ContentLength = strPost.Length;
//objRequest.Timeout = 1000000;
//objRequest.KeepAlive = false;
HttpWebResponse objResponse =
(HttpWebResponse)objRequest.GetResponse();
string str;
string strHold;
using (StreamReader sr = new
StreamReader(objResponse.GetResponseStream()))
{
strHold = sr.ReadToEnd().ToString();
sr.Close();
}
objRequest.Abort();
XmlDocument doc = new XmlDocument();
doc.LoadXml(strHold );
XmlNodeList nodelist = doc.GetElementsByTagName("item");
for (int i = 0; i < nodelist.Count; i++)
{
XmlTags XmlTags1 = new XmlTags();
XmlTags1.Title = nodelist.Item(i).ChildNodes[0].InnerText;
XmlTags1.Link = nodelist.Item(i).ChildNodes[1].InnerText;
XmlTags1.Description =
nodelist.Item(i).ChildNodes[2].InnerText;
string strtest =
XmlTags1.Description.Substring(XmlTags1.Description.IndexOf("</a>"));
XmlTags1.Description = strtest.Replace("</a>","");
string str2 = nodelist.Item(i).ChildNodes[2].InnerText;
XmlTags1.DescLink =
nodelist.Item(i).ChildNodes[2].InnerText.Substring(9,
nodelist.Item(i).ChildNodes[2].InnerText.IndexOf("><img src=")-10);
XmlTags1.ImageLink =
nodelist.Item(i).ChildNodes[2].InnerText.Substring(nodelist.Item(i).ChildNodes[2].InnerText.IndexOf("><img
src=") + 11, str2.LastIndexOf("rss=1") -
nodelist.Item(i).ChildNodes[2].InnerText.IndexOf("><img src=") - 6);
XmlTags1.Author =
nodelist.Item(i).ChildNodes[3].InnerText;
XmlTags1.Date = nodelist.Item(i).ChildNodes[4].InnerText;
myList.Add(XmlTags1);
}
objResponse.Close();
return myList;
}
}