473,657 Members | 2,445 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

HttpWebRequest from winform

I have code which works as an asp.net page that posts an
xml file to web page and gets a response back.

When the the calls GetResponse() it goes into the page
it's posting to to and works fine. When it's been ported
to a winform it doesn't work on the GetResponse() call.

I think it probably needs credentials but not sure what
to use, tried a few ids w/o any luck.

The asp.net page as well as the winform are on the same
server for now but will later be on seperate servers.

Thanks,

Brian
Nov 22 '05 #1
10 2754
Brian Brown <bb****@hotmail .com> wrote:
I have code which works as an asp.net page that posts an
xml file to web page and gets a response back.

When the the calls GetResponse() it goes into the page
it's posting to to and works fine. When it's been ported
to a winform it doesn't work on the GetResponse() call.

I think it probably needs credentials but not sure what
to use, tried a few ids w/o any luck.

The asp.net page as well as the winform are on the same
server for now but will later be on seperate servers.


Could you post a short but complete program which demonstrates the
problem?

See http://www.pobox.com/~skeet/csharp/complete.html for details of
what I mean by that.

--
Jon Skeet - <sk***@pobox.co m>
http://www.pobox.com/~skeet
If replying to the group, please do not mail me too
Nov 22 '05 #2
Web page code that works:

Imports System.IO
Imports System.Xml
Imports System.Xml.Sche ma
Imports System.Net.Cred entialCache
Imports System.Text
Imports System.net

Public Class Class1
Private Sub SendDoc(ByRef sData As String)
Const k_send_to_url As String
= "http://localhost/Reader/Receive.aspx"

Dim request_obj As HttpWebRequest
Dim request_stream As Stream
Dim response_obj As HttpWebResponse
Dim xml_reader As XmlTextReader
Dim docobj As New XmlDocument
Try
request_obj = CType(WebReques t.Create
(k_send_to_url) , HttpWebRequest)

request_obj.Met hod = "POST"
request_obj.Con tentType = "text/xml"
request_obj.Tim eout = 999999999
request_obj.All owWriteStreamBu ffering = True

request_stream = request_obj.Get RequestStream
()

docobj.LoadXml( sData)

docobj.Save(req uest_stream)

request_stream. Close()
docobj = Nothing

response_obj = request_obj.Get Response()

xml_reader = New XmlTextReader
(response_obj.G etResponseStrea m())
docobj = New XmlDocument
docobj.Load(xml _reader)

request_obj = Nothing
request_stream = Nothing
response_obj = Nothing

Catch ex As Exception
Exit Sub
End Try

End Sub
End Class

Windows code that doesn't:
Imports System.IO
Imports System.Xml
Imports System.Xml.Sche ma
Imports System.Net.Cred entialCache
Imports System.Text
Imports System.net

Public Class Class1

Private Sub SendDoc(ByRef sData As String)
Const k_send_to_url As String
= "http://localhost/Reader/Receive.aspx"

Dim request_obj As HttpWebRequest
Dim request_stream As Stream
Dim response_obj As HttpWebResponse
Dim xml_reader As XmlTextReader
Dim docobj As New XmlDocument
Try
request_obj = CType(WebReques t.Create
(k_send_to_url) , HttpWebRequest)

request_obj.Met hod = "POST"
request_obj.Con tentType = "text/xml"
request_obj.Tim eout = 999999999
request_obj.All owWriteStreamBu ffering = True

request_stream = request_obj.Get RequestStream
()

docobj.LoadXml( sData)

docobj.Save(req uest_stream)

request_stream. Close()
docobj = Nothing

response_obj = request_obj.Get Response()

xml_reader = New XmlTextReader
(response_obj.G etResponseStrea m())
docobj = New XmlDocument
docobj.Load(xml _reader)

request_obj = Nothing
request_stream = Nothing
response_obj = Nothing

Catch ex As Exception
Exit Sub
End Try
End Sub
End Class

-----Original Message-----
Brian Brown <bb****@hotmail .com> wrote:
I have code which works as an asp.net page that posts an xml file to web page and gets a response back.

When the the calls GetResponse() it goes into the page
it's posting to to and works fine. When it's been ported to a winform it doesn't work on the GetResponse() call.

I think it probably needs credentials but not sure what to use, tried a few ids w/o any luck.

The asp.net page as well as the winform are on the same server for now but will later be on seperate servers.
Could you post a short but complete program which

demonstrates theproblem?

See http://www.pobox.com/~skeet/csharp/complete.html for details ofwhat I mean by that.

--
Jon Skeet - <sk***@pobox.co m>
http://www.pobox.com/~skeet
If replying to the group, please do not mail me too
.

Nov 22 '05 #3
<an*******@disc ussions.microso ft.com> wrote:

<snip>
Windows code that doesn't:


And what happens, exactly? I notice that when you catch an exception,
you don't do anything with it - is an exception being thrown? If so,
what's the contents of the exception?

--
Jon Skeet - <sk***@pobox.co m>
http://www.pobox.com/~skeet
If replying to the group, please do not mail me too
Nov 22 '05 #4

When the response_obj = request_obj.Get Response()

code executes if you put a breakpoint on it, it should
post the xml file to the page defined in k_send_to_url.

This happens in the web version but not in the windows
version which I intend to turn into a windows service.

No error is thrown until I try to use the result which
should be an xml document.

It has to be security somehow I guess, but can't seem to
figure out what. I tried setting credentials and it still
didn't work.

Thanks!
-----Original Message-----
<an*******@disc ussions.microso ft.com> wrote:

<snip>
Windows code that doesn't:
And what happens, exactly? I notice that when you catch

an exception,you don't do anything with it - is an exception being thrown? If so,what's the contents of the exception?

--
Jon Skeet - <sk***@pobox.co m>
http://www.pobox.com/~skeet
If replying to the group, please do not mail me too
.

Nov 22 '05 #5
<an*******@disc ussions.microso ft.com> wrote:
When the response_obj = request_obj.Get Response()

code executes if you put a breakpoint on it, it should
post the xml file to the page defined in k_send_to_url.

This happens in the web version but not in the windows
version which I intend to turn into a windows service.

No error is thrown until I try to use the result which
should be an xml document.

It has to be security somehow I guess, but can't seem to
figure out what. I tried setting credentials and it still
didn't work.


You haven't said what *does* happen in the Windows version though. What
happens you you execute request_obj.Get Response()? What does it return?
Does it block? Does it throw an exception?

--
Jon Skeet - <sk***@pobox.co m>
http://www.pobox.com/~skeet
If replying to the group, please do not mail me too
Nov 22 '05 #6
Nothing happens, no error, it doesn't go into the other
page, the error is on the next line when it expects an
xml document and there's nothing.

-----Original Message-----
<an*******@disc ussions.microso ft.com> wrote:
When the response_obj = request_obj.Get Response()

code executes if you put a breakpoint on it, it should
post the xml file to the page defined in k_send_to_url.

This happens in the web version but not in the windows
version which I intend to turn into a windows service.

No error is thrown until I try to use the result which
should be an xml document.

It has to be security somehow I guess, but can't seem to figure out what. I tried setting credentials and it still didn't work.
You haven't said what *does* happen in the Windows

version though. Whathappens you you execute request_obj.Get Response()? What does it return?Does it block? Does it throw an exception?

--
Jon Skeet - <sk***@pobox.co m>
http://www.pobox.com/~skeet
If replying to the group, please do not mail me too
.

Nov 22 '05 #7
<an*******@disc ussions.microso ft.com> wrote:
Nothing happens, no error, it doesn't go into the other
page, the error is on the next line when it expects an
xml document and there's nothing.


I suggest you look at the contents of the stream then, and find out
what's in there. Also look at your webserver logs to find out whether
it thinks it sent any content back - and preferably what it thought it
received, too.

--
Jon Skeet - <sk***@pobox.co m>
http://www.pobox.com/~skeet
If replying to the group, please do not mail me too
Nov 22 '05 #8
It doesn't even go into the page. I have a breakpoint
where in the asp page it goes into the calling page, the
windows one doesn't even go into the page.

-----Original Message-----
<an*******@disc ussions.microso ft.com> wrote:
Nothing happens, no error, it doesn't go into the other page, the error is on the next line when it expects an
xml document and there's nothing.
I suggest you look at the contents of the stream then,

and find outwhat's in there. Also look at your webserver logs to find out whetherit thinks it sent any content back - and preferably what it thought itreceived, too.

--
Jon Skeet - <sk***@pobox.co m>
http://www.pobox.com/~skeet
If replying to the group, please do not mail me too
.

Nov 22 '05 #9
<an*******@disc ussions.microso ft.com> wrote:
It doesn't even go into the page. I have a breakpoint
where in the asp page it goes into the calling page, the
windows one doesn't even go into the page.


And yet GetResponse returns with no exception? What status does the
returned response have?

--
Jon Skeet - <sk***@pobox.co m>
http://www.pobox.com/~skeet
If replying to the group, please do not mail me too
Nov 22 '05 #10

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

10
472
by: Brian Brown | last post by:
I have code which works as an asp.net page that posts an xml file to web page and gets a response back. When the the calls GetResponse() it goes into the page it's posting to to and works fine. When it's been ported to a winform it doesn't work on the GetResponse() call. I think it probably needs credentials but not sure what to use, tried a few ids w/o any luck.
9
8176
by: Mike Cronin via DotNetMonster.com | last post by:
Hi there, Can anyone tell me what level of encryption is used when making an HTTPS POST request through an instance of the System.Net.HttpWebRequest object? Thanks much in advance! Mike Cronin Data On Call - Programmer
1
3559
by: Curtis Justus | last post by:
Hello, I tried posting this in the aspnet.security group, but it seemed like some posts in this group are closer to what I'm looking for. In any event, I apologize in advance if this isn't the place to post this... I have a winform app that is using HttpWebRequest to connect to a site using SSL (i.e. "https://..."). The vendor requires me to validate some information on the client certificate I get from their server (to make sure...
16
12634
by: thomas peter | last post by:
I am building a precache engine... one that request over 100 pages on an remote server to cache them remotely... can i use the HttpWebRequest and WebResponse classes for this? or must i use the MSHTML objects to really load the HTML and request all of the images on site? string lcUrl = http://www.cnn.com; // *** Establish the request
6
4181
by: Mike Koerner | last post by:
Hi, I am having problems setting the HttpWebRequest Date header. I understand that it is a restricted header and I do receive the "This header must be modified with the appropriate property." Is there a way to make sure that the date header is sent over or a way to work around this exception? Here's a sample of the code:
1
1439
by: SP | last post by:
I need to make an httpwebrequest in a winform. The first call is ok, and it is in GET. The second must use the cookie of the first call and then POST data to a uri. The are some sample code for manage cookies?
2
16355
by: steveS | last post by:
Hi all, I'm having trouble connecting to a Java web service using HttpWebRequest. I get the error message "The request was aborted: Could not create SSL/TLS secure channel". The Java service requires a client certificate which they have provided in .cer format. I can connect ok to their test service which uses SSL but doesnt require a client certificate with the code below. I dont have great deal of knowledge about client certificates...
0
1700
by: steveS | last post by:
Hi all, I'm having trouble connecting to a Java web service using HttpWebRequest. I get the error message "The request was aborted: Could not create SSL/TLS secure channel". The Java service requires a client certificate which they have provided in .cer format. I can connect ok to their test service which uses SSL but doesnt require a client certificate with the code below. I dont have great deal of knowledge about client certificates...
1
4002
by: moo | last post by:
Is there a simple way to get my logon credentials to make my web request work through our proxy server? I tried CredentialCache.DefaultCredentials, but I get nothing back. I can get it to work if I just create a new NetworkCredential object specifying user, password and domain. But, I would rather get that info automatically if possible, rather than presenting a winform for them to type it in. Lastly, why do both the request object and...
1
8025
by: Proogeren | last post by:
I have a problem with a httpwebrequest that I am creating. The request in itself looks correct but using fiddler I see that a www-authentication header is sent along as well. The code is pasted below. I do not add any www-authentication header here so I was wondering if anyone knows how to remove it. I have used almost 2 days trying to figure this out so help would be highly appreciated. CORRECT No proxy-authenticate header is present no...
0
8826
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...
0
8732
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
8503
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
8605
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
7330
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...
0
5632
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4306
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
2726
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
1955
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.