473,399 Members | 3,106 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,399 software developers and data experts.

GetRequestStream hangs

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<XmlTagstags1 = 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[i].Description + "<br>");
string strPost = "Hello";
//System.Net.WebProxy objProxy1 = new
System.Net.WebProxy("http://usushproxy01:80");
objRequest =
(HttpWebRequest)WebRequest.Create(tags1[i].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<HtmlMetaMeta1 = 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<XmlTagsmyList = 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.Descriptio n.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;
}
}

Mar 7 '07 #1
1 4680
Thus wrote ra*******@gmail.com,
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.
There are a few potential bugs in your code (see below), and I don't think
that POST is the right thing to do here anyway.

But for your purpose, you're better off using WebClient.UploadValues() if
you really need to POST.
Default.aspx
---------------------
XmlParse test1 = new XmlParse();// see the code below for
xmlparse.cs

List<XmlTagstags1 = 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[i].Description + "<br>");
string strPost = "Hello";
//System.Net.WebProxy objProxy1 = new
System.Net.WebProxy("http://usushproxy01:80");
objRequest =
(HttpWebRequest)WebRequest.Create(tags1[i].DescLink );
//objRequest.Proxy = objProxy;
objRequest.Method = "POST";
objRequest.ContentType = "application/x-www-form-
urlencoded";
objRequest.ContentLength = strPost.Length;
That's dangerous. You assume that your string length equals the post size,
but that may or may not be true depending on the character encoding. And
both headers don't apply in the GET case.
//objRequest.Timeout = 1000000;
//objRequest.KeepAlive = false;
StreamWriter myWriter = new
StreamWriter(objRequest.GetRequestStream());
myWriter.Flush();
Why's that?
myWriter.Write(strPost);
Note that you should URL encode POST data.

Cheers,
--
Joerg Jooss
ne********@joergjooss.de
Mar 9 '07 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

10
by: Tomas Vera | last post by:
Hello All, I'ma having trouble getting GetCurrentProcess() to work properly. What I'm trying to accomplish is list all running processes. But my call get GetProcesses() hangs. While testing...
0
by: Questions | last post by:
(can't find any of my previous post for same issue. please CC to my email address as well. Thanks!) Hi all, What is the possible reason that HttpWebRequest.GetRequestStream() may hang there...
3
by: Jason | last post by:
I'm having a hard time getting a call to HttpWebRequest's GetRequestSteam to work. Each time I try to run it, I get the following error: The underlying connection was closed: Unable to...
0
by: a_newcomb | last post by:
I have an application which polls and connects to a webserver on a background thread. When the application is supposed to exit, I call abort on the HttpWebRequest object. I have observed that...
8
by: Jim Toth | last post by:
I have a multithreaded application that is posting XML requests to a remote web site. As more and more calls are made to HttpWebRequest.GetRequestStream, the length of time increases for each call...
6
by: Alexander Widera | last post by:
hello, if i start a program (an exe-file) with Process.Start(...) I don't have the required permissions that the programm needs (i could start the programm but the program needs special rights)....
3
by: Mike Markiewicz | last post by:
I need help from someone who's familiar with HttpWebRequest. I'm trying to extract data from a website that requires you to log in. I'm using the GetRequestStream method to send the POST data. ...
2
by: Pierre Rouleau | last post by:
Hi all, I have a consistent test case where os.popen3() hangs in Windows. The system hangs when retrieving the lines from the child process stdout. I know there were several reports related to...
2
by: ZadaheaD | last post by:
Hello, i really need your help on this one. im trying to pass an XML by a web service using HttpWebRequest and a POST Method. here is my code : HttpWebRequestObj =...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.