Home All Groups Group Topic Archive Search About

POSTing data with System.Windows.Forms.WebBrowser: Vista vs XP

Author
8 Mar 2007 5:04 AM
Jeff
I have a C# Winforms app developed with Visual Studio Express Edition
that uses a WebBrowser control to POST data to an external website.
Here is some sample code:

  string postStr = "parm1=hello";
  postStr += "&parm2=world";
  byte[] postBytes =Encoding.UTF8.GetBytes(postStr);
  WebBrowser webBrowser = new WebBrowser();
         webBrowser.Navigate("http://www.mydomain.com/post_here",
"_blank", postBytes, "Content-Type: application/x-www-form-urlencoded"
+ "\n" + "\r");


This works just fine when the app runs in Windows XP, but with Vista,
the data isn't properly posted.  After further investigation, I did a
network trace (with ethereal), and discovered that while the XP
instance sent a HTTP POST with my data (correct), Vista sent a HTTP
GET, resulting in the error.  Is there a known issue with
System.Windows.Forms.WebBrowser POSTing data on Vista?

Author
10 Mar 2007 1:49 AM
Patrick Steele
In article <1173330298.838714.90***@p10g2000cwp.googlegroups.com>,
j***@kalikstein.com says...
> I have a C# Winforms app developed with Visual Studio Express Edition
> that uses a WebBrowser control to POST data to an external website.

I would try using the WebRequest classes for this sort of thing. 
Probably much lighter than the WebBrowser class and you'll have more
control:

http://tinyurl.com/99v7

Author
10 Mar 2007 2:02 AM
Jeff
On Mar 9, 7:49 pm, Patrick Steele <patr***@mvps.org> wrote:
> In article <1173330298.838714.90***@p10g2000cwp.googlegroups.com>,
> j***@kalikstein.com says...
>
> > I have a C# Winforms app developed with Visual Studio Express Edition
> > that uses a WebBrowser control to POST data to an external website.
>
> I would try using the WebRequest classes for this sort of thing.
> Probably much lighter than the WebBrowser class and you'll have more
> control:
>

Thanks for your response, Patrick.  I think the WebBrowser control is
appropriate for my application, because I was the user to be navigated
to the POSTed page.  I had a fully functional implementation that
suited my needs for Windows XP, but the same code doesn't work in
Vista, so I really do think this is a bug that should be addressed.
In any event, I worked around the problem by having my program create
a .html file embedded with javascript POSTing code and then
WebBrowser.Navigate-ing to the html file.

-jeff
Author
10 Mar 2007 2:16 AM
Patrick Steele
In article <1173492137.137223.192***@v33g2000cwv.googlegroups.com>,
j***@kalikstein.com says...
> Thanks for your response, Patrick.  I think the WebBrowser control is
> appropriate for my application, because I was the user to be navigated
> to the POSTed page.

Ahhh.  I see.  Yeah, if you need to do browsing too, the WebBrowser
class is what you need.

> In any event, I worked around the problem by having my program create
> a .html file embedded with javascript POSTing code and then
> WebBrowser.Navigate-ing to the html file.

Glad you got it fixed!


AddThis Social Bookmark Button