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

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 1701
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

9
by: Swami | last post by:
I was wondering how I can programmatically find out the path of an installed program. I have an application that needs access to a config file that resides in the folder of another application. ...
20
by: Randall Arnold | last post by:
I've got an asp.net page that dynamically generates an html table on the server side. On the client side, I need to copy the rendered table to the clipboard programmatically (using vbscript). I...
3
by: Paul | last post by:
I am using Visual Studio.net 2005 (and asp.net 2.0) Let's say that in a Web Project, I have created a (Dataset?) called SomeDataset.xsd. On it I have a TableAdapter called SomeTableTableAdapter...
1
by: Siva | last post by:
Hi, In my ASP.Net 2.0 app, I have a gridview whose data is being populated using an object data source which retrieves data from a data access layer. The Select method returns a static list of...
0
by: Rob C | last post by:
I wrote a Web Service in C# using VS2005. I created a connection to a SQL Server database table using the TableAdaptor wizards. I then exposed a Web Method called "GetResidents()" that returned a...
10
by: perplexed | last post by:
After a user logs in (ASP.NET 2.0 membership/roles), how do I programmatically access their UserId and other information stored in the ASP.NET database structure? A user may login at Login.aspx...
0
by: JasonDelft | last post by:
Hi, I am working on an application in vs2005 (vb.net) where i need to start another program (an .exe file on my harddrive) and call functions from that program in the current vb.net application. ...
4
by: ma | last post by:
Hello, I want to inject a piece of JavaScript inside a table cell. How can I do this? The table is statically created on master page.
2
by: Chris Ashley | last post by:
I have a .NET Windows Service which needs to log on to another machine to access a UNC share. Is this possible? I assume so due to the existence of the NetworkCredential class, but I can't find any...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
0
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...

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.