473,396 Members | 2,036 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,396 software developers and data experts.

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 2713
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.com>
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.Schema
Imports System.Net.CredentialCache
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(WebRequest.Create
(k_send_to_url), HttpWebRequest)

request_obj.Method = "POST"
request_obj.ContentType = "text/xml"
request_obj.Timeout = 999999999
request_obj.AllowWriteStreamBuffering = True

request_stream = request_obj.GetRequestStream
()

docobj.LoadXml(sData)

docobj.Save(request_stream)

request_stream.Close()
docobj = Nothing

response_obj = request_obj.GetResponse()

xml_reader = New XmlTextReader
(response_obj.GetResponseStream())
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.Schema
Imports System.Net.CredentialCache
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(WebRequest.Create
(k_send_to_url), HttpWebRequest)

request_obj.Method = "POST"
request_obj.ContentType = "text/xml"
request_obj.Timeout = 999999999
request_obj.AllowWriteStreamBuffering = True

request_stream = request_obj.GetRequestStream
()

docobj.LoadXml(sData)

docobj.Save(request_stream)

request_stream.Close()
docobj = Nothing

response_obj = request_obj.GetResponse()

xml_reader = New XmlTextReader
(response_obj.GetResponseStream())
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.com>
http://www.pobox.com/~skeet
If replying to the group, please do not mail me too
.

Nov 22 '05 #3
<an*******@discussions.microsoft.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.com>
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.GetResponse()

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*******@discussions.microsoft.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.com>
http://www.pobox.com/~skeet
If replying to the group, please do not mail me too
.

Nov 22 '05 #5
<an*******@discussions.microsoft.com> wrote:
When the response_obj = request_obj.GetResponse()

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.GetResponse()? What does it return?
Does it block? Does it throw an exception?

--
Jon Skeet - <sk***@pobox.com>
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*******@discussions.microsoft.com> wrote:
When the response_obj = request_obj.GetResponse()

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.GetResponse()? What does it return?Does it block? Does it throw an exception?

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

Nov 22 '05 #7
<an*******@discussions.microsoft.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.com>
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*******@discussions.microsoft.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.com>
http://www.pobox.com/~skeet
If replying to the group, please do not mail me too
.

Nov 22 '05 #9
<an*******@discussions.microsoft.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.com>
http://www.pobox.com/~skeet
If replying to the group, please do not mail me too
Nov 22 '05 #10
<an*******@discussions.microsoft.com> wrote:
HttpWebResponse.statusmessage = ok

same for HttpWebResponse.statuscode

yet it never went into the page, nor does it contain the
returned content.


In that case, I suggest you find what it *did* go to. Does it contain
*any* content? My guess is that perhaps a proxy is getting in the way
unexpectedly.

Try using a network sniffer to find out what's going on.

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

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

Similar topics

10
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....
9
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...
1
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...
16
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...
6
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." ...
1
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...
2
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...
0
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...
1
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...
1
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...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
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,...
0
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...
0
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,...
0
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...
0
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...
0
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,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 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 a new...

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.