473,804 Members | 2,101 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Accessing a URI programmaticall y

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 programmaticall y, using the
System.Net.WebC lient 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.Http WebRequest.Chec kFinalStatus()
System.Net.Http WebRequest.EndG etResponse(IAsy ncResult
asyncResult)
System.Net.Http WebRequest.GetR esponse()
WebRequestProto .Client.Button1 _Click(Object sender,
EventArgs e) in
c:\inetpub\wwwr oot\flare\flare citycouncil\fla redirect\clien
t.aspx.cs:114
System.Web.UI.W ebControls.Butt on.OnClick(Even tArgs e)

System.Web.UI.W ebControls.Butt on.System.Web.U I.IPostBackEve
ntHandler.Raise PostBackEvent(S tring eventArgument)
System.Web.UI.P age.RaisePostBa ckEvent
(IPostBackEvent Handler sourceControl, String eventArgument)
System.Web.UI.P age.RaisePostBa ckEvent
(NameValueColle ction postData)
System.Web.UI.P age.ProcessRequ estMain()
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 1740
Hi Helen,

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

Maybe you need to set the WebClient.BaseA ddress 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.c om> 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 programmaticall y, using the
System.Net.WebC lient 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.Http WebRequest.Chec kFinalStatus()
System.Net.Http WebRequest.EndG etResponse(IAsy ncResult
asyncResult)
System.Net.Http WebRequest.GetR esponse()
WebRequestProto .Client.Button1 _Click(Object sender,
EventArgs e) in
c:\inetpub\wwwr oot\flare\flare citycouncil\fla redirect\clien
t.aspx.cs:114
System.Web.UI.W ebControls.Butt on.OnClick(Even tArgs e)

System.Web.UI.W ebControls.Butt on.System.Web.U I.IPostBackEve
ntHandler.Raise PostBackEvent(S tring eventArgument)
System.Web.UI.P age.RaisePostBa ckEvent
(IPostBackEvent Handler sourceControl, String eventArgument)
System.Web.UI.P age.RaisePostBa ckEvent
(NameValueColle ction postData)
System.Web.UI.P age.ProcessRequ estMain()
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.Http WebRequest.Crea te("www.microso ft.com");
objResponse = objRequest.GetR esponse();
StreamReader sr = new
StreamReader(ob jResponse.GetRe sponseStream(), System.Text.Enc oding.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.WebR esponse objResponse;
System.Net.Http WebRequest myReq =(HttpWebReques t)
System.Net.Http WebRequest.Crea te(this.TextBox 3.Text);

objResponse = myReq.GetRespon se();

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.Htt pWebRequest.Cre ate("www.micros oft.com");
objResponse = objRequest.GetR esponse();
StreamReader sr = new
StreamReader(o bjResponse.GetR esponseStream (),System.Text. Encoding.Defaul t); 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.WebC lient objClient = new System.Net.WebC lient
();
objClient.BaseA ddress = "http://2k3btest/CGI-Bin/nph-
srep.exe?SCHPAG E=c:/inetpub/wwwroot/cgi-
bin/pennies.sch&Gro up=U&Name=penni es";

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

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.BaseA ddress 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/frlrfSystemNetW ebClientClassBa seAddressTopic.
asp

"Helen" <sc************ ******@nospam.c om> 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 programmaticall y, using the System.Net.WebC lient 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.Http WebRequest.Chec kFinalStatus()
System.Net.Http WebRequest.EndG etResponse(IAsy ncResult
asyncResult)
System.Net.Http WebRequest.GetR esponse()
WebRequestProto .Client.Button1 _Click(Object sender,
EventArgs e) in
c:\inetpub\wwwr oot\flare\flare citycouncil\fla redirect\clien t.aspx.cs:114
System.Web.UI.W ebControls.Butt on.OnClick(Even tArgs e)

System.Web.UI.W ebControls.Butt on.System.Web.U I.IPostBackEve ntHandler.Raise PostBackEvent(S tring eventArgument)
System.Web.UI.P age.RaisePostBa ckEvent
(IPostBackEvent Handler sourceControl, String eventArgument) System.Web.UI.P age.RaisePostBa ckEvent
(NameValueColle ction postData)
System.Web.UI.P age.ProcessRequ estMain()
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
1923
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. I'm guessing that this can be done by accessing the registry, but some articles or sample code would be useful. Thanks.
20
3525
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 just need to be pointed toward a resource for accessing the DOM this way. I must be searching on the wrong keywords because so far I can't find anything helpful, even on Microsoft's site. My development environment is Visual Web developer...
3
1962
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 and a query called GetSomeInfoQuery. In an aspx page I used an ObjectDataSource, and chose as the business object SomeDataSetTableAdapters.SomeTableTableAdapter, then the method GetSomeInfoQuery.
1
1776
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 orders. The order contains a bunch of data retrieved from SQL server. I do display only a part of them in my Gridview by using <asp:BoundField. I do , however need to access the remaining fields which are part of the order programmatically from my...
0
898
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 dataset of resident records. I then created a website in a separate project and added a reference to the web service component. I added a GridView to a ASPX page and bound it to the dataset returned from the GetResidents call. When I pull up...
10
4870
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 and then they are redirected to somepage.aspx. somepage.aspx doesn't have a reference to the login object and can't access UserId. Also, are there any issues with changing the UserId column from a uniqueidentifier to an integer IDENT? Thanks.
0
972
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. The way that i am doing it now is the following: I add a reference to the program via the "add reference" option in the solution explorer.After that i can use the program in my vb code like any other class i have in my project . Example:the...
4
2860
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
1416
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 associated class to access the share using a NetworkCredential object?
0
9714
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9594
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10600
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
1
10351
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
10096
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
9174
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
4311
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
3834
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
3002
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.