0

I would like my C# desktop application to send a POST containing a file to a website (out of my control).

Then the application should open the RESPONSE in the default browser.

I havn't been able to achieve this. Is it even possible?

So far I've tried the following approaches with no success:

  • I created a HTML page that automatically sent a POST FORM via JS. I then opened it using Process.Start(). The problem is that I can't specify the path to the FILE input field. So a dead end.

  • I used WebClient.UploadValues(...), and the wrote the response to a static local HTML file. Then I opened the HTML file using Process.Start(). The problem is that no images, cookies and such are present so I ended up with a dead static local HTML page.

  • I used WebClient.UploadValues(...), but I seem incapable of redirecting the RESPONSE to a browser.

Any help would be greatly appreciated!

Yuliam Chandra
  • 14,494
  • 12
  • 52
  • 67
bagerth
  • 1
  • 1
  • Why do you need to show the response to the client? Is there any further step that the user must take on the web? – Oscar Sep 09 '14 at 07:42
  • @Oscar The web site is an online shop containing four steps in order to complete an order. My application sends a POST request for step one, so the response will take the end-user directly to step two. – bagerth Sep 09 '14 at 08:44
  • And I supose they don't have a public API.. Have you tried with the WebBrowser Control? You could set it to post the file at first, and later let the user take control of the rest.. – Oscar Sep 09 '14 at 08:55
  • @Oscar I have been unsuccessful trying to use WebBrowser, but I'll try it again. If you have any suggestion on how to make it work with WebBrowser, feel free to post it :) Thanks so far! – bagerth Sep 09 '14 at 09:24
  • WebBrowser control will be my first choice in this case. If you have any comments about why your first try was unsuccessful, I'll be happy to help. – Oscar Sep 09 '14 at 10:01
  • @Oscar I'm using the following code to create a POST from a webBrowser: `var webBrowser = new WebBrowser();` `String parameters = "param1=param1value&param2=param2value";` `byte[] byte1 = System.Text.Encoding.UTF8.GetBytes(parameters); webBrowser.Navigate(url, "_SELF", byte1, "Content-Type: application/x-www-form-urlencoded");` So for so good! But I havn't yet been able to create a POST with a file. – bagerth Sep 09 '14 at 11:40
  • You need this overloaded version of Navigate to post data: http://msdn.microsoft.com/en-us/library/ms161355(v=vs.110).aspx See this post too: http://support.microsoft.com/kb/174923/es – Oscar Sep 09 '14 at 11:46
  • @Oscar After many attempts I havn't yet been able to create a postdata parameter containing a file. My current code: `var webBrowser = new WebBrowser(); String postdata = "xslfile=pathToFile"; byte[] byte1 = System.Text.Encoding.UTF8.GetBytes(postdata); webBrowser.Navigate(url, "_SELF", byte1, "Content-Type: application/x-www-form-urlencoded");` The POST is done correctly, but I havn't found any information on how to upload a file automatically using this method. Any suggestions would be appreciated! – bagerth Sep 09 '14 at 12:23
  • Sorry, it seems that it was possible in previous versions, but was removed for security reasons.. http://stackoverflow.com/questions/18687876/c-sharp-webbrowser-control-uploading-files-not-working-need-assistance – Oscar Sep 09 '14 at 13:49

0 Answers0