473,699 Members | 2,715 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

HttpWebResponse Problems

ok, heres the problem.. i have an asp.net page that im using to kind of
relay information back and forth. So on the Page_Load i make a request to a
webservice and return some xml back to the first calling app. now... i wrote
a test app to try it out, but i cannot get the proper data from it. It
always says the the ContentLength is -1 so my my StreamReader.Re adToEnd
throws an exception.. heres the chunk of code in the driver app:

webRequest = (HttpWebRequest )WebRequest.Cre ate(webRequestS erver);

webRequest.Meth od = "POST";

webRequest.Cont entLength = doc.InnerXml.Le ngth;

webRequest.Cont entType = "text/xml";

webRequest.Keep Alive = false;

myWriter = new StreamWriter(we bRequest.GetReq uestStream());

myWriter.Write( doc.InnerXml.To String());

myWriter.Close( );

webResponse = (HttpWebRespons e)webRequest.Ge tResponse();
StreamReader myReader = new StreamReader(we bResponse.GetRe sponseStream()) ;
responseFromSer ver = myReader.ReadTo End();

myReader.Close( );

Im thinking the problem is on the asp page. A weird thing i came across is
that it wont let me do a XmlDoc.Save on the response. so what i end up doing
is this:

myXMLDoc.LoadXm l("xmlString" )

responseXML = myXMLDoc.Docume ntElement

Response.Clear( )

Response.Buffer Output = True

Response.Conten tType = "text/xml"

responseXML.Wri teTo(New XmlTextWriter(R esponse.Output) )

Response.Flush( )

Response.Close( )

I tried adding and appending a ContentLength Header to the response, but no
good.. and you can set the content-type fine. but there is no property for
Content-Length.

so what do i do

thanx for any help
Nov 17 '05 #1
3 1962
Try "Response.E nd" at the very bottom of your code.
"Sean Chapman" <sc******@inlan dkwpp.com> wrote in message
news:b9jmb.1613 7$EO3.3695@clgr ps13...
ok, heres the problem.. i have an asp.net page that im using to kind of
relay information back and forth. So on the Page_Load i make a request to a webservice and return some xml back to the first calling app. now... i wrote a test app to try it out, but i cannot get the proper data from it. It
always says the the ContentLength is -1 so my my StreamReader.Re adToEnd
throws an exception.. heres the chunk of code in the driver app:

webRequest = (HttpWebRequest )WebRequest.Cre ate(webRequestS erver);

webRequest.Meth od = "POST";

webRequest.Cont entLength = doc.InnerXml.Le ngth;

webRequest.Cont entType = "text/xml";

webRequest.Keep Alive = false;

myWriter = new StreamWriter(we bRequest.GetReq uestStream());

myWriter.Write( doc.InnerXml.To String());

myWriter.Close( );

webResponse = (HttpWebRespons e)webRequest.Ge tResponse();
StreamReader myReader = new StreamReader(we bResponse.GetRe sponseStream()) ;
responseFromSer ver = myReader.ReadTo End();

myReader.Close( );

Im thinking the problem is on the asp page. A weird thing i came across is
that it wont let me do a XmlDoc.Save on the response. so what i end up doing is this:

myXMLDoc.LoadXm l("xmlString" )

responseXML = myXMLDoc.Docume ntElement

Response.Clear( )

Response.Buffer Output = True

Response.Conten tType = "text/xml"

responseXML.Wri teTo(New XmlTextWriter(R esponse.Output) )

Response.Flush( )

Response.Close( )

I tried adding and appending a ContentLength Header to the response, but no good.. and you can set the content-type fine. but there is no property for
Content-Length.

so what do i do

thanx for any help

Nov 17 '05 #2
Maybe this example will help you.

<%@ Strict=True %>
<%@ Import Namespace="Syst em.Net" %>
<%@ Import Namespace="Syst em.IO" %>
<html>
<script language="vb" runat="server">

Sub button_click(se nder as object, e as EventArgs)

Dim mgWebRequest As HttpWebRequest
Dim stringPost, stringResult As String
Dim mgStreamWriter As StreamWriter
Dim mgWebResponse As HttpWebResponse
Dim mgStreamReader As StreamReader

'Send Data to other form

mgWebRequest=CT ype(WebRequest. Create(otherpag e.text),HttpWeb Request)

stringPost = senddata.text
if stringPost.leng th = 0 then
mgWebRequest.Me thod = "GET"
else
mgWebRequest.Me thod = "POST"
mgWebRequest.Co ntentLength = stringPost.leng th 'length
mgWebRequest.Co ntentType = "applicatio n/x-www-form-urlencoded"
mgStreamWriter = Nothing
mgStreamWriter = New StreamWriter(mg WebRequest.GetR equestStream())
mgStreamWriter. Write(stringPos t)
mgStreamWriter. Close()
end if
mgWebResponse = CType(mgWebRequ est.GetResponse (),HttpWebRespo nse)
mgStreamReader = New StreamReader(mg WebResponse.Get ResponseStream( ))
stringResult=(m gStreamReader.R eadToEnd())
mgStreamReader. Close()
response.write( stringResult)
end sub
</script>
<body>
<form runat="server">
Enter site data (including http://)
<asp:textbox id="otherpage" width ="500"
text="http://search.msn.com/results.asp?" runat="server"/><br>
Enter Post Data
<asp:textbox id="senddata" width ="500"
text="RS=CHECKE D&FORM=MSNH&v=1 &q=shoes" runat="server"/><br>
<asp:button id="send" text="send" onclick="button _click" runat="server"/>
</form>
</body>
</html>
"Sean Chapman" <sc******@inlan dkwpp.com> wrote in message
news:b9jmb.1613 7$EO3.3695@clgr ps13...
ok, heres the problem.. i have an asp.net page that im using to kind of
relay information back and forth. So on the Page_Load i make a request to a webservice and return some xml back to the first calling app. now... i wrote a test app to try it out, but i cannot get the proper data from it. It
always says the the ContentLength is -1 so my my StreamReader.Re adToEnd
throws an exception.. heres the chunk of code in the driver app:

webRequest = (HttpWebRequest )WebRequest.Cre ate(webRequestS erver);

webRequest.Meth od = "POST";

webRequest.Cont entLength = doc.InnerXml.Le ngth;

webRequest.Cont entType = "text/xml";

webRequest.Keep Alive = false;

myWriter = new StreamWriter(we bRequest.GetReq uestStream());

myWriter.Write( doc.InnerXml.To String());

myWriter.Close( );

webResponse = (HttpWebRespons e)webRequest.Ge tResponse();
StreamReader myReader = new StreamReader(we bResponse.GetRe sponseStream()) ;
responseFromSer ver = myReader.ReadTo End();

myReader.Close( );

Im thinking the problem is on the asp page. A weird thing i came across is
that it wont let me do a XmlDoc.Save on the response. so what i end up doing is this:

myXMLDoc.LoadXm l("xmlString" )

responseXML = myXMLDoc.Docume ntElement

Response.Clear( )

Response.Buffer Output = True

Response.Conten tType = "text/xml"

responseXML.Wri teTo(New XmlTextWriter(R esponse.Output) )

Response.Flush( )

Response.Close( )

I tried adding and appending a ContentLength Header to the response, but no good.. and you can set the content-type fine. but there is no property for
Content-Length.

so what do i do

thanx for any help

Nov 17 '05 #3
thanx.. that fixed it
"Tohid" <To********@hot mail.com> wrote in message
news:%2******** ********@TK2MSF TNGP09.phx.gbl. ..
Try "Response.E nd" at the very bottom of your code.
"Sean Chapman" <sc******@inlan dkwpp.com> wrote in message
news:b9jmb.1613 7$EO3.3695@clgr ps13...
ok, heres the problem.. i have an asp.net page that im using to kind of
relay information back and forth. So on the Page_Load i make a request to
a
webservice and return some xml back to the first calling app. now... i

wrote
a test app to try it out, but i cannot get the proper data from it. It
always says the the ContentLength is -1 so my my StreamReader.Re adToEnd
throws an exception.. heres the chunk of code in the driver app:

webRequest = (HttpWebRequest )WebRequest.Cre ate(webRequestS erver);

webRequest.Meth od = "POST";

webRequest.Cont entLength = doc.InnerXml.Le ngth;

webRequest.Cont entType = "text/xml";

webRequest.Keep Alive = false;

myWriter = new StreamWriter(we bRequest.GetReq uestStream());

myWriter.Write( doc.InnerXml.To String());

myWriter.Close( );

webResponse = (HttpWebRespons e)webRequest.Ge tResponse();
StreamReader myReader = new

StreamReader(we bResponse.GetRe sponseStream()) ;

responseFromSer ver = myReader.ReadTo End();

myReader.Close( );

Im thinking the problem is on the asp page. A weird thing i came across is that it wont let me do a XmlDoc.Save on the response. so what i end up

doing
is this:

myXMLDoc.LoadXm l("xmlString" )

responseXML = myXMLDoc.Docume ntElement

Response.Clear( )

Response.Buffer Output = True

Response.Conten tType = "text/xml"

responseXML.Wri teTo(New XmlTextWriter(R esponse.Output) )

Response.Flush( )

Response.Close( )

I tried adding and appending a ContentLength Header to the response, but

no
good.. and you can set the content-type fine. but there is no property for Content-Length.

so what do i do

thanx for any help


Nov 17 '05 #4

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

Similar topics

0
2114
by: Denny Rue | last post by:
I’ve created VB code to download files from a web site through the use of HTTPWebRequest, HTTPWebResponse and BinaryReader. The HTTPWebRequest has a TimeOut property to limit how long it waits for a corresponding HTTPWebResponse. This works just fine. However, the timeout does not appear to apply to a BinaryReader created from the HTTPWebResponse. I’ve had instances where the procedures will hang indefinitely during the download. ...
0
10323
by: hlabbott | last post by:
Hi I'm having a problem displaying attachments correctly. I have messages with attachments stored on Exchange2000 and want to be able to click a hyperlink in my project like in OWA and see an attachment. Because it is stored on Exchange I have to set a username and password so I do a GET request. The data I get back seems to still be encoded - trying to open an excel file for example results in it trying to open it but an excel...
13
9812
by: Jason Manfield | last post by:
For some URLs (e.g.http://v3.espacenet.com/origdoc?DB=EPODOC&IDX=WO2005028634&F=0&QPN=WO2005028634), the content length for the HttpWebResponse I get with request.GetResponse in empty. The response.GetResponseStream() also empty. However, I am able to open the URL in the browser (the URL address remains the same; it is not redirected) Here is the code snippet: HttpWebRequest req = (HttpWebRequest)WebRequest.Create(pageAddress);
1
3303
by: Jason Manfield | last post by:
Why does HttpWebResponse.CharacterSet always return ISO-8859-1? I am accessing a Chinese Web site (http://cn.yahoo.com) -- View Source in IE shows the character set to be "gb2312", but the HttpWebResponse shows it to be ISO-8859-1. Websites like www.cnn.com also show the character set to ISO-8859-1 Here is the code snippet: string pageAddress = "http://cn.yahoo.com"; HttpWebRequest req = (HttpWebRequest)WebRequest.Create(pageAddress);
3
4658
by: Nuno Magalhaes | last post by:
Hello, In a simple thread I have a code like the one below: public void ProtectionRun() { while(true) { //Sleep thread for one minute //Thread.Sleep(60000); HttpWebRequest
2
2598
by: Noggin The Nog | last post by:
Hi all, I've been trying to get HttpWebResponse to work, but whenever I try I get "The operation has timed-out". I'm simply trying to send an HTTP request querystring to a remote website and read back the single string it returns (OK/Not-Ok)! It seems such a simple thing to do, but I've been on this for hours now! Here's the code I'm trying: Dim myRequest As HttpWebRequest Dim myResponse As HttpWebResponse
1
4028
by: Brent | last post by:
I thought I was doing a simple thing, here -- asking a server for a text document, getting the first 150 lines, and then returning the lines. But I keep getting timeout errors: "Exception Details: System.Net.WebException: The operation has timed-out." I read somewhere that generally these errors come from not closing a HTTPWebResponse connection before opening another. But -- to my knowledge -- I've shut down connections in every way I...
2
1135
by: Brent | last post by:
I'm having odd problems with the HttpWebResponse class. Some servers are quite speedy, while others don't seem to want to talk to my code. Consider the following pages*: http://planetbrent.com/test.aspx?url=http://www.yahoo.com http://planetbrent.com/test.aspx?url=http://www.msn.com http://planetbrent.com/test.aspx?url=http://www.sec.gov...
2
2383
by: Nuno Magalhaes | last post by:
In pages that there is no content length, how does HttpWebResponse knows where the page ends? And what kind of objects/methods does it retrieve? Does it only retrieve the initial page without any images, i.e., does it only makes one "GET / HTTP/1.1\r\n\r\n"? Because I'm doing some projects on a webclient (to measure some statistic times) and the total bytes get byte HttpWebResponse are lower than the total objects I get via socket way. ...
0
8685
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9172
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
9032
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
8908
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
8880
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
7745
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
4626
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
3054
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
3
2008
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.