Send HTTP message with default browser from C #

I am wondering if it is possible to send POST data with the default browser of a computer in C #.

Here is the situation. My client would like their C # application to open their browser and send the client information to a web form. This web form will be behind the login screen. The assumption on the application side is that as soon as the client data is sent to the login screen, the login screen will transfer this information to the web form to pre-fill it. This would be done via HTTPS, and the client would like it to be done using POST rather than GET, as the client information will be sent as plain text.

I found some great solutions that do POSTS and handle requests. As an example http://geekswithblogs.net/rakker/archive/2006/04/21/76044.aspx

Thus, the TL version; DR will be

1) Open browser

2) Open the url with POST data

Thank you for your help,

Floor

+4
source share
4 answers

I handled a similar situation once, creating an HTML page on the fly with customizing the form with hidden values ​​for everything. There was a bit of Javascript on the page so that it uploads a form when it loads, so it sends data as needed.

I suspect this method will work for you.

  • Creating a dictionary of fields and values
  • Creating an HTML page using Javascript to automatically submit when the page loads
  • Burn page to temporary location on disk
  • Launch the default browser with this page.

Remember that this POST data is also sent in clear text. POST is usually suitable for more than a few fields, as you can hold more data (2048 bytes per URL limit) and that your user has a friendly URL to see in their browser.

+5
source

Nothing is sent as plain text when using SSL, it is encrypted. If you do not set what the default browser is (IE, Firefox, Chrome, etc.), you will need to find out what the default browser is and use its API to do this work (if possible).

It is likely that it will be faster and more efficient to open the default browser by calling the URL using the Start Process and passing the information in the query string (this is done by GET instead of POST, which I know isn't what you're asking for).

The response from the server can be redirected, and the redirection can send a completed form (saving values ​​in a session or something like that).

Thus, the complexity is transferred to the website, and not to the Windows application, which should be easier to update if something goes wrong.

NTN

0
source

Can you compile your logic in C # and then call it from PowerShell? From PowerShell, you can very easily automate Internet Explorer . This is only IE, but you can also use WaitnN .

0
source

Everything you specify at the end of the URL is counted as a query string that populates the GET. It is more visible than the POSTed data in the body, but not more secure with respect to the sniffer.

So, in short, no.

-1
source

Source: https://habr.com/ru/post/1334580/


All Articles