Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

C# Open web page in default browser with post data

Tags:

c#

http-post

I am sure this must have been answered before but I cannot find a solution, so I figure I am likely misunderstanding other people's solutions or trying to do something daft, but here we go.

I am writing an add-in for Outlook 2010 in C# where a user can click a button in the ribbon and submit the email contents to a web site. When they click the button the website should open in the default browser, thus allowing them to review what has just been submitted and interact with it on the website. I am able to do this using query strings in the URL using:

System.Diagnostics.Process.Start("http://www.test.com?something=value");

but the limit on the amount of data that can be submitted and the messy URLs are preventing me from following through with this approach. I would like to use an HTTP POST for this as it is obviously more suitable. However, the methods I have found for doing this do not seem to open the page up in the browser after submitting the post data:

http://msdn.microsoft.com/en-us/library/debx8sh9.aspx

to summarise; the user needs to be able to click the button in the Outlook ribbon, have the web browser open and display the contents of the email which have been submitted via POST.

EDIT:

Right, I found a way to do it, its pretty fugly but it works! Simply create a temporary .html file (that is then launched as above) containing a form with hidden fields for all the data, and have it submitted on page load with JavaScript.

I don't really like this solution as it relies on JavaScript (I have a <noscript> submit button just in case) and seems like a bit of a bodge, so I am still really hoping someone on here will come up with something better.

like image 739
Ben Avatar asked Apr 10 '12 14:04

Ben


People also ask

What C is used for?

C programming language is a machine-independent programming language that is mainly used to create many types of applications and operating systems such as Windows, and other complicated programs such as the Oracle database, Git, Python interpreter, and games and is considered a programming foundation in the process of ...

Is C language easy?

C is a general-purpose language that most programmers learn before moving on to more complex languages. From Unix and Windows to Tic Tac Toe and Photoshop, several of the most commonly used applications today have been built on C. It is easy to learn because: A simple syntax with only 32 keywords.

What is the full name of C?

In the real sense it has no meaning or full form. It was developed by Dennis Ritchie and Ken Thompson at AT&T bell Lab. First, they used to call it as B language then later they made some improvement into it and renamed it as C and its superscript as C++ which was invented by Dr.

Is C programming hard?

C is more difficult to learn than JavaScript, but it's a valuable skill to have because most programming languages are actually implemented in C. This is because C is a “machine-level” language. So learning it will teach you how a computer works and will actually make learning new languages in the future easier.


1 Answers

The Dropbox client does it the same ways as you mentioned in your EDIT. But it also does some obfuscation, i.e. it XORs the data with the hash submitted via the URL.

Here are the steps how Dropbox does it:

  1. in-app: Create a token that can be used to authorize at dropbox.com.
  2. in-app: Convert token to hex string (A).
  3. in-app: Create a secure random hex string (B) of the same length.
  4. in-app: Calculate C = A XOr B.
  5. in-app: Create temporary HTML file with the following functionality:
  6. A hidden input field which contains value B.
  7. A submit form with hidden input fields necessary for login to dropbox.com.
  8. A JS function that reads the hash from URI, XORs it with B and writes the result to the submit forms hidden fields.
  9. Delete hash from URI.
  10. Submit form.
  11. in-app: Open the temporary HTML file with the standard browser and add C as hash to the end of the URI.

Now if your browser opens the HTML file it calculates the auth token from the hidden input field and the hash in the URI and opens dropbox.com. And because of Point 5.4. you are not able to hit the back button in your browser to login again because the hash is gone.

like image 118
Nicolas Göddel Avatar answered Sep 30 '22 17:09

Nicolas Göddel