472,371 Members | 1,440 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 472,371 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 1654
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...
2
by: Kemmylinns12 | last post by:
Blockchain technology has emerged as a transformative force in the business world, offering unprecedented opportunities for innovation and efficiency. While initially associated with cryptocurrencies...
0
by: antdb | last post by:
Ⅰ. Advantage of AntDB: hyper-convergence + streaming processing engine In the overall architecture, a new "hyper-convergence" concept was proposed, which integrated multiple engines and...
0
by: Arjunsri | last post by:
I have a Redshift database that I need to use as an import data source. I have configured the DSN connection using the server, port, database, and credentials and received a successful connection...
1
by: Matthew3360 | last post by:
Hi, I have been trying to connect to a local host using php curl. But I am finding it hard to do this. I am doing the curl get request from my web server and have made sure to enable curl. I get a...
0
Oralloy
by: Oralloy | last post by:
Hello Folks, I am trying to hook up a CPU which I designed using SystemC to I/O pins on an FPGA. My problem (spelled failure) is with the synthesis of my design into a bitstream, not the C++...
0
by: Carina712 | last post by:
Setting background colors for Excel documents can help to improve the visual appeal of the document and make it easier to read and understand. Background colors can be used to highlight important...
0
BLUEPANDA
by: BLUEPANDA | last post by:
At BluePanda Dev, we're passionate about building high-quality software and sharing our knowledge with the community. That's why we've created a SaaS starter kit that's not only easy to use but also...
2
by: Ricardo de Mila | last post by:
Dear people, good afternoon... I have a form in msAccess with lots of controls and a specific routine must be triggered if the mouse_down event happens in any control. Than I need to discover what...
1
by: Johno34 | last post by:
I have this click event on my form. It speaks to a Datasheet Subform Private Sub Command260_Click() Dim r As DAO.Recordset Set r = Form_frmABCD.Form.RecordsetClone r.MoveFirst Do If...

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.