473,395 Members | 1,936 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,395 software developers and data experts.

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.ReadToEnd
throws an exception.. heres the chunk of code in the driver app:

webRequest = (HttpWebRequest)WebRequest.Create(webRequestServer );

webRequest.Method = "POST";

webRequest.ContentLength = doc.InnerXml.Length;

webRequest.ContentType = "text/xml";

webRequest.KeepAlive = false;

myWriter = new StreamWriter(webRequest.GetRequestStream());

myWriter.Write(doc.InnerXml.ToString());

myWriter.Close();

webResponse = (HttpWebResponse)webRequest.GetResponse();
StreamReader myReader = new StreamReader(webResponse.GetResponseStream());
responseFromServer = myReader.ReadToEnd();

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.LoadXml("xmlString")

responseXML = myXMLDoc.DocumentElement

Response.Clear()

Response.BufferOutput = True

Response.ContentType = "text/xml"

responseXML.WriteTo(New XmlTextWriter(Response.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 1950
Try "Response.End" at the very bottom of your code.
"Sean Chapman" <sc******@inlandkwpp.com> wrote in message
news:b9jmb.16137$EO3.3695@clgrps13...
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.ReadToEnd
throws an exception.. heres the chunk of code in the driver app:

webRequest = (HttpWebRequest)WebRequest.Create(webRequestServer );

webRequest.Method = "POST";

webRequest.ContentLength = doc.InnerXml.Length;

webRequest.ContentType = "text/xml";

webRequest.KeepAlive = false;

myWriter = new StreamWriter(webRequest.GetRequestStream());

myWriter.Write(doc.InnerXml.ToString());

myWriter.Close();

webResponse = (HttpWebResponse)webRequest.GetResponse();
StreamReader myReader = new StreamReader(webResponse.GetResponseStream());
responseFromServer = myReader.ReadToEnd();

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.LoadXml("xmlString")

responseXML = myXMLDoc.DocumentElement

Response.Clear()

Response.BufferOutput = True

Response.ContentType = "text/xml"

responseXML.WriteTo(New XmlTextWriter(Response.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="System.Net" %>
<%@ Import Namespace="System.IO" %>
<html>
<script language="vb" runat="server">

Sub button_click(sender 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=CType(WebRequest.Create(otherpage.tex t),HttpWebRequest)

stringPost = senddata.text
if stringPost.length = 0 then
mgWebRequest.Method = "GET"
else
mgWebRequest.Method = "POST"
mgWebRequest.ContentLength = stringPost.length 'length
mgWebRequest.ContentType = "application/x-www-form-urlencoded"
mgStreamWriter = Nothing
mgStreamWriter = New StreamWriter(mgWebRequest.GetRequestStream())
mgStreamWriter.Write(stringPost)
mgStreamWriter.Close()
end if
mgWebResponse = CType(mgWebRequest.GetResponse(),HttpWebResponse)
mgStreamReader = New StreamReader(mgWebResponse.GetResponseStream())
stringResult=(mgStreamReader.ReadToEnd())
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=CHECKED&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******@inlandkwpp.com> wrote in message
news:b9jmb.16137$EO3.3695@clgrps13...
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.ReadToEnd
throws an exception.. heres the chunk of code in the driver app:

webRequest = (HttpWebRequest)WebRequest.Create(webRequestServer );

webRequest.Method = "POST";

webRequest.ContentLength = doc.InnerXml.Length;

webRequest.ContentType = "text/xml";

webRequest.KeepAlive = false;

myWriter = new StreamWriter(webRequest.GetRequestStream());

myWriter.Write(doc.InnerXml.ToString());

myWriter.Close();

webResponse = (HttpWebResponse)webRequest.GetResponse();
StreamReader myReader = new StreamReader(webResponse.GetResponseStream());
responseFromServer = myReader.ReadToEnd();

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.LoadXml("xmlString")

responseXML = myXMLDoc.DocumentElement

Response.Clear()

Response.BufferOutput = True

Response.ContentType = "text/xml"

responseXML.WriteTo(New XmlTextWriter(Response.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********@hotmail.com> wrote in message
news:%2****************@TK2MSFTNGP09.phx.gbl...
Try "Response.End" at the very bottom of your code.
"Sean Chapman" <sc******@inlandkwpp.com> wrote in message
news:b9jmb.16137$EO3.3695@clgrps13...
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.ReadToEnd
throws an exception.. heres the chunk of code in the driver app:

webRequest = (HttpWebRequest)WebRequest.Create(webRequestServer );

webRequest.Method = "POST";

webRequest.ContentLength = doc.InnerXml.Length;

webRequest.ContentType = "text/xml";

webRequest.KeepAlive = false;

myWriter = new StreamWriter(webRequest.GetRequestStream());

myWriter.Write(doc.InnerXml.ToString());

myWriter.Close();

webResponse = (HttpWebResponse)webRequest.GetResponse();
StreamReader myReader = new

StreamReader(webResponse.GetResponseStream());

responseFromServer = myReader.ReadToEnd();

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.LoadXml("xmlString")

responseXML = myXMLDoc.DocumentElement

Response.Clear()

Response.BufferOutput = True

Response.ContentType = "text/xml"

responseXML.WriteTo(New XmlTextWriter(Response.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
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...
0
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...
13
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...
1
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...
3
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
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...
1
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...
2
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*: ...
2
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...
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...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
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
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
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...
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.