简体   繁体   中英

Use HTML string from Server Requets, and create the web page without saving it a file [in C#]

I´m sending the value of a variable via POST to a PHP page in C#. I get the data stream from the server that has all the web page in HTML with the value of the POST. This information is stored in a string variable.

I would like to open a browser and show the web page (maybe using System.Diagnostics.Process.Start("URL") ), without having to save it in a file, this is showing the page in the moment and, when the browser is closed, no file is stored in the server.

Any idea?

Drop a WebBrowser control into a new form webBrowser1 and set its DocumentTextProperty to your result html

webBrowser1.DocumentText = ("<html><body>hello world</body></html>");

source:

<html><body>hello world</body></html>

在此处输入图片说明

You aren't going to be able to do that in an agnostic way.

If you simply wanted to open the URL in a browser, then using the Process class would work.

Unfortunately, in your case, you already have the content from creating the POST to the server, and you really want to stream that response in your application to the browser.

It's possible among the some browsers, but it's not able to be done in an agnostic way (and it's complicated even when targeting a specific browser).

To complicate matters, you want the browser to believe that the stream you are sending it is really coming from the server, when in reality, it's not.

I believe that your best bet would be to save the response to the file system in a temp file. However, before you do, add the <base> tag to the file with the URL that the file came from. This way, relative URLs will resolve correctly when rendered in the browser.

Then, just open the temporary file in the browser using the Process class.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM