0

I have a desktop application that has some classes, which I want to serialize and send to a webpage when a user clicks a button in the desktop C# application.

The data is too long for an argument. What I want to achieve here is, how do I post it and open the website on the clients PC with the dynamic changes made by the sent data ?

Need some suggestions or guidance to proceed in the right direction.

Dhrumil
  • 3,221
  • 6
  • 21
  • 34
GregH
  • 141
  • 1
  • 1
  • 8
  • possible duplicate of [How to post data to a website](http://stackoverflow.com/questions/8538810/how-to-post-data-to-a-website) – Legends Apr 28 '15 at 21:27
  • @Legends I don't think it is duplicate of generic "how to post data in C#" - "open the website on the clients PC with the dynamic changes made by the sent data" sounds like trying to open browser essentially with results of post request. – Alexei Levenkov Apr 28 '15 at 21:32
  • There are two parts to your question, which one do you need ? posting the data or opening a webpage from your application ? – Shashank Shekhar Apr 28 '15 at 21:37
  • actually the problem is explained in that post, and he can use a browser control in case of win forms, or open a browser using process.start with the url as a parameter – Legends Apr 28 '15 at 22:01
  • @GregH, do consider marking an answer if any of it helped you. – Amit May 05 '15 at 04:53

3 Answers3

1

You can use HttpClient

For example:

using (var client = new HttpClient())
{
    client.BaseAddress = new Uri("http://myUrl");
    var gizmo = new Product() { Name = "Gizmo", Price = 100, Category = "Widget" };
    response = await client.PostAsJsonAsync("api/products", gizmo);
    if (response.IsSuccessStatusCode)
    {
        //do something
    }
}
Amit
  • 25,106
  • 25
  • 75
  • 116
0

One option would be to generate local page with form that contains data and "action=POST" pointing to your site. Than set script that automatically submit this form and as result you'll have data send by browser and browser will continue as if it is normal POST request.

Alexei Levenkov
  • 98,904
  • 14
  • 127
  • 179
0

If you don't like HttpClient you can also use WebClient which is a convenience wrapper for your exact scenario.

Peter Wone
  • 17,965
  • 12
  • 82
  • 134