请问高手如何让WebBrowser直接显示变量内容
本帖最后由 shii_u 于 2013-01-04 09:38:11 编辑
private void btReport_Track_Click(object sender, RoutedEventArgs e)
{
try
{
Int32 Main_Type = Convert.ToInt32(CBMain_Track.SelectedValue.ToString());//CBMain_Track是combox
string MAIN_TYPE = "";
if (Main_Type == 0) MAIN_TYPE = "ALLMAIN";
if (Main_Type == 1) MAIN_TYPE = "维护";
if (Main_Type == 2) MAIN_TYPE = "维修";
//MAIN_TYPE是中文,这里处理一下
MAIN_TYPE = HttpUtility.UrlEncode(MAIN_TYPE);//避免参数出现乱码
string str = string.Format("http://" + PulicCls.StrAIX_IP + "/ReportServer/Pages/ReportViewer.aspx?/Machine/CheckPoints_TrackStati&MAIN_TYPE={1}", MAIN_TYPE);
System.Windows.Forms.WebBrowser frame;
frame = windowsFormHost2.Child as System.Windows.Forms.WebBrowser;
//通过HTTP Request来发送请求的时候,要用HttpResponse.CharacterSet来获取ContentType中的编码参数,然后再读取HTTP Response包中的内容,再加上上面的转换方法,可以手动发送HTTP包并将结果显示到WebBrowser中
var request = (HttpWebRequest)WebRequest.Create(str);
var response = (HttpWebResponse)request.GetResponse();
using (var stream = response.GetResponseStream())
//通过HttpResponse.CharacterSet获取HTTP包的编码
using (var reader = new System.IO.StreamReader(stream, Encoding.GetEncoding(response.CharacterSet)))
{
var all = reader.ReadToEnd();
//使用ConvertExtendedASCII方法
all= ConvertExtendedASCII(all);
//
这里该如何处理,让frame直接显示all的内容
}
}
catch (Exception err)
{ MessageBox.Show(err.Message); }
}
public static string ConvertExtendedASCII(string HTML)
{
string retVal = "";
char[] s = HTML.ToCharArray();
foreach (char c in s)
{
if (Convert.ToInt32(c) > 127)
&nbs