Posted By: SlackmasterK | Dec 8th, 2008 @ 12:50 PM
page 1 of 1
Comments: 2 | Views: 1650
SlackmasterK
SlackmasterK
I write my OWN blogging engines

  I have a Winform with a BackgroundWorker. The BackgroundWorker, among other things, has to make an HTTP call to a page, fill out some data, submit the form, and retrieve the HTML that comes back after "clicking" the submit button. I've run into a number of roadblocks while doing this:

1. Can't POST the data because the target webserver doesn't 405 support that method.
2. Can't use a WebClient.UploadValues, again, because the webserver doesn't support POST. Can't use UploadValues with verb type GET because I get the error "System.Net.ProtocolViolationException: Cannot send a content-body with this verb-type."
3. Can't use a WebBrowser control because BackgroundWorkers suck at COM Interop and an exception is thrown that says it must be in a STA thread (Single-Threaded Apartment)
4. Can't run another seperate thread because the BW has to sit and wait for the result before it can continue (Can't, or at least I don't know a way to do this that won't crash)
5. Can't change the ApartmentState of the thread because it's a BackgroundWorker and it throws if told to go to STA mode.

This requirement (call page, log in, return result at landing page) is only a tiny piece of what this background thread actually does... In fact it's one part of about 20 different things that have to be done on this thread.

The app entrypoint is already tagged with the [STAThread] attribute.

What else can I do to resolve this?

ZippyV
ZippyV
Fired Up
If you use the GET method can't you put all the form's values in the url?

http://www.example.com/login.aspx?name=foo&password=bar
page 1 of 1
Comments: 2 | Views: 1650
Microsoft Communities