469,569 Members | 1,545 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,569 developers. It's quick & easy.

Accessing a URI programmatically

Hi,
I am trying to write an ASP.Net application that
integrates with a third party application via their fairly
simplistic web component, however I am having problems
with the URI.

The URI works fine in Internet Explorer, and returns the
information from the third party application to the
browser, which is displayed, no problems.

However, when I try to do this programmatically, using the
System.Net.WebClient class OpenRead, or the System.Net.
HTTPWebRequest class GetResponse, I get the following Web
Exception:

WebException: The underlying connection was closed: The
server committed an HTTP protocol violation.]
System.Net.HttpWebRequest.CheckFinalStatus()
System.Net.HttpWebRequest.EndGetResponse(IAsyncRes ult
asyncResult)
System.Net.HttpWebRequest.GetResponse()
WebRequestProto.Client.Button1_Click(Object sender,
EventArgs e) in
c:\inetpub\wwwroot\flare\flarecitycouncil\flaredir ect\clien
t.aspx.cs:114
System.Web.UI.WebControls.Button.OnClick(EventArgs e)

System.Web.UI.WebControls.Button.System.Web.UI.IPo stBackEve
ntHandler.RaisePostBackEvent(String eventArgument)
System.Web.UI.Page.RaisePostBackEvent
(IPostBackEventHandler sourceControl, String eventArgument)
System.Web.UI.Page.RaisePostBackEvent
(NameValueCollection postData)
System.Web.UI.Page.ProcessRequestMain()
Can anyone tell me what these HTTP client classes do
differently from Internet Explorer, which is perfectly
happy with the URI? and how I can find out what the
protocol violation is?

Thanks

Helen
Nov 18 '05 #1
5 1573
Hi Helen,

Is it possible that your code isn't passing the method the complete URI?

Maybe you need to set the WebClient.BaseAddress property down to the page?
There's a sample here that shows what I mean:

http://msdn.microsoft.com/library/de...dressTopic.asp
"Helen" <sc******************@nospam.com> wrote in message
news:00****************************@phx.gbl...
Hi,
I am trying to write an ASP.Net application that
integrates with a third party application via their fairly
simplistic web component, however I am having problems
with the URI.

The URI works fine in Internet Explorer, and returns the
information from the third party application to the
browser, which is displayed, no problems.

However, when I try to do this programmatically, using the
System.Net.WebClient class OpenRead, or the System.Net.
HTTPWebRequest class GetResponse, I get the following Web
Exception:

WebException: The underlying connection was closed: The
server committed an HTTP protocol violation.]
System.Net.HttpWebRequest.CheckFinalStatus()
System.Net.HttpWebRequest.EndGetResponse(IAsyncRes ult
asyncResult)
System.Net.HttpWebRequest.GetResponse()
WebRequestProto.Client.Button1_Click(Object sender,
EventArgs e) in
c:\inetpub\wwwroot\flare\flarecitycouncil\flaredir ect\clien
t.aspx.cs:114
System.Web.UI.WebControls.Button.OnClick(EventArgs e)

System.Web.UI.WebControls.Button.System.Web.UI.IPo stBackEve
ntHandler.RaisePostBackEvent(String eventArgument)
System.Web.UI.Page.RaisePostBackEvent
(IPostBackEventHandler sourceControl, String eventArgument)
System.Web.UI.Page.RaisePostBackEvent
(NameValueCollection postData)
System.Web.UI.Page.ProcessRequestMain()
Can anyone tell me what these HTTP client classes do
differently from Internet Explorer, which is perfectly
happy with the URI? and how I can find out what the
protocol violation is?

Thanks

Helen

Nov 18 '05 #2
Hello Helen,

Thanks for posting in the group.

Based on my understanding, now the question is: How to use .NET framework
class to get HTTP response in ASP.NET programming? If I have misunderstood
the problem, please feel free to post here.

About how to do it in ASP.NET, please refer to the following code sample:
[C#]
string sBuffer;
WebResponse objResponse;
WebRequest objRequest =
System.Net.HttpWebRequest.Create("www.microsoft.co m");
objResponse = objRequest.GetResponse();
StreamReader sr = new
StreamReader(objResponse.GetResponseStream(),Syste m.Text.Encoding.Default);
sBuffer = sr.ReadToEnd();
sr.Close();

Could you please test the above code and let me know if it works? I suggest
you test it for a simple page first.

Does that answer your question?

Best regards,
Yanhong Huang
Microsoft Online Partner Support

Get Secure! C www.microsoft.com/security
This posting is provided "AS IS" with no warranties, and confers no rights.

Nov 18 '05 #3
Hi Huang,
Your code works fine if I access a simple web page that I
wrote, but I am still getting the same problem when I link
to the URL that I'm trying to access.

Here is my new code:

System.Net.WebResponse objResponse;
System.Net.HttpWebRequest myReq =(HttpWebRequest)
System.Net.HttpWebRequest.Create(this.TextBox3.Tex t);

objResponse = myReq.GetResponse();

At this point it crashes with the original error message.

I suspect that the other application I'm trying to access
is causing the Server Protocol Violation, but I need to
find out what it is doing that the HTTPWebRequest is
objecting to, since Internet Explorer seems to be
perfectly happy with the URL.

Thanks ..

Helen
-----Original Message-----
Hello Helen,

Thanks for posting in the group.

Based on my understanding, now the question is: How to use .NET framework class to get HTTP response in ASP.NET programming? If I have misunderstood the problem, please feel free to post here.

About how to do it in ASP.NET, please refer to the following code sample:[C#]
string sBuffer;
WebResponse objResponse;
WebRequest objRequest =
System.Net.HttpWebRequest.Create("www.microsoft.c om");
objResponse = objRequest.GetResponse();
StreamReader sr = new
StreamReader(objResponse.GetResponseStream (),System.Text.Encoding.Default); sBuffer = sr.ReadToEnd();
sr.Close();

Could you please test the above code and let me know if it works? I suggest you test it for a simple page first.

Does that answer your question?

Best regards,
Yanhong Huang
Microsoft Online Partner Support

Get Secure! C www.microsoft.com/security
This posting is provided "AS IS" with no warranties, and confers no rights.
.

Nov 18 '05 #4
Hi Ken,

I have tried setting the baseaddress explicitly, though
the OpenRead method takes the whole address anyway.

Also, this code works fine if I access a test page I wrote
myself, it is only causing a problem when I access the
application I'm trying to integrate to, unfortunately!

Here is my code.

System.Net.WebClient objClient = new System.Net.WebClient
();
objClient.BaseAddress = "http://2k3btest/CGI-Bin/nph-
srep.exe?SCHPAGE=c:/inetpub/wwwroot/cgi-
bin/pennies.sch&Group=U&Name=pennies";

Stream stResponse = objClient.OpenRead
("http://2k3btest/CGI-Bin/nph-srep.exe?
SCHPAGE=c:/inetpub/wwwroot/cgi-
bin/pennies.sch&Group=U&Name=pennies");

At this point it crashes with the WebException : The
Server Committed an HTTP Protocol Violation.

I'm guessing that the other application is somehow
violating HTTP, but Internet Explorer is quite happy with
the URL, and returns the data I need in my asp.net
appication.

Any other ideas how I can find out what the problem is?

Thanks

Helen
-----Original Message-----
Hi Helen,

Is it possible that your code isn't passing the method the complete URI?
Maybe you need to set the WebClient.BaseAddress property down to the page?There's a sample here that shows what I mean:

http://msdn.microsoft.com/library/default.asp? url=/library/en-
us/cpref/html/frlrfSystemNetWebClientClassBaseAddressTopic.
asp

"Helen" <sc******************@nospam.com> wrote in message
news:00****************************@phx.gbl...
Hi,
I am trying to write an ASP.Net application that
integrates with a third party application via their fairly simplistic web component, however I am having problems
with the URI.

The URI works fine in Internet Explorer, and returns the
information from the third party application to the
browser, which is displayed, no problems.

However, when I try to do this programmatically, using the System.Net.WebClient class OpenRead, or the System.Net.
HTTPWebRequest class GetResponse, I get the following Web Exception:

WebException: The underlying connection was closed: The
server committed an HTTP protocol violation.]
System.Net.HttpWebRequest.CheckFinalStatus()
System.Net.HttpWebRequest.EndGetResponse(IAsyncRes ult
asyncResult)
System.Net.HttpWebRequest.GetResponse()
WebRequestProto.Client.Button1_Click(Object sender,
EventArgs e) in
c:\inetpub\wwwroot\flare\flarecitycouncil\flaredir ect\clien t.aspx.cs:114
System.Web.UI.WebControls.Button.OnClick(EventArgs e)

System.Web.UI.WebControls.Button.System.Web.UI.IPo stBackEve ntHandler.RaisePostBackEvent(String eventArgument)
System.Web.UI.Page.RaisePostBackEvent
(IPostBackEventHandler sourceControl, String eventArgument) System.Web.UI.Page.RaisePostBackEvent
(NameValueCollection postData)
System.Web.UI.Page.ProcessRequestMain()
Can anyone tell me what these HTTP client classes do
differently from Internet Explorer, which is perfectly
happy with the URI? and how I can find out what the
protocol violation is?

Thanks

Helen

.

Nov 18 '05 #5
Hi Helen,

Thanks for the quick response.

I understand the problem is quite annoying. Based on my experience, it is
better for us to simply that page step by step to isolate the problem. IE
is smart enough to determine what to do under different situations, such as
proxy involved, authentication needed, and etc.

To dig into the root cause, we may need to use Network Monitor to catch
network packets to see what happens in the low level. It needs more time.
However, it is very straightford and quite useful under some situations.

If you have any more concerns, please feel free to post here.

Best regards,
Yanhong Huang
Microsoft Community Support

Get Secure! C www.microsoft.com/security
This posting is provided "AS IS" with no warranties, and confers no rights.

Nov 18 '05 #6

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

9 posts views Thread by Swami | last post: by
reply views Thread by Rob C | last post: by
10 posts views Thread by perplexed | last post: by
4 posts views Thread by ma | last post: by
2 posts views Thread by Chris Ashley | last post: by
reply views Thread by suresh191 | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.