Accessing a URI programmatically

H

Helen

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(IAsyncResult
asyncResult)
System.Net.HttpWebRequest.GetResponse()
WebRequestProto.Client.Button1_Click(Object sender,
EventArgs e) in
c:\inetpub\wwwroot\flare\flarecitycouncil\flaredirect\clien
t.aspx.cs:114
System.Web.UI.WebControls.Button.OnClick(EventArgs e)

System.Web.UI.WebControls.Button.System.Web.UI.IPostBackEve
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
 
Y

Yan-Hong Huang[MSFT]

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.com");
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.
 
H

Helen

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.Text);

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
 
G

Guest

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 said:
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(IAsyncResult
asyncResult)
System.Net.HttpWebRequest.GetResponse()
WebRequestProto.Client.Button1_Click(Object sender,
EventArgs e) in
c:\inetpub\wwwroot\flare\flarecitycouncil\flaredirect\clien
t.aspx.cs:114
System.Web.UI.WebControls.Button.OnClick(EventArgs e)

System.Web.UI.WebControls.Button.System.Web.UI.IPostBackEve
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


.
 
Y

Yan-Hong Huang[MSFT]

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.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,994
Messages
2,570,223
Members
46,812
Latest member
GracielaWa

Latest Threads

Top