System.Net.WebClient wc = new System.Net.WebClient();
string webData = wc.DownloadString(absuri);
从浏览器下载html后,我正在使用Microsoft Translator翻译文本。之后,我想在浏览器中显示它。
我需要在浏览器中替换webRequest
响应数据,请在此帮助我。
string txtToTranslate = TextBox1.Text;
string uri = "http://api.microsofttranslator.com/v2/Http.svc/Translate?text="
+ System.Web.HttpUtility.UrlEncode(txtToTranslate)
+ "&from=en&to=es";
System.Net.WebRequest translationWebRequest = System.Net.WebRequest.Create(uri);
translationWebRequest.Headers.Add("Authorization", headerValue);
System.Net.WebResponse response = null;
response = translationWebRequest.GetResponse();
System.IO.Stream stream = response.GetResponseStream();
System.Text.Encoding encode = System.Text.Encoding.GetEncoding("utf-8");
System.IO.StreamReader translatedStream = new System.IO.StreamReader(stream, encode)
System.Xml.XmlDocument xTranslation = new System.Xml.XmlDocument()
xTranslation.LoadXml(translatedStream.ReadToEnd());
string resdata = xTranslation.InnerText;
WebBrowser webBrowser = new WebBrowser();
webBrowser.DocumentStream = stream;
答案 0 :(得分:0)
您现在使用的WebBrowser
控件是Windows窗体或WPF控件,而不是ASP.NET控件,它似乎是您要求的。
如果要将任何内容返回给浏览器,则必须设置当前HTTP上下文的响应:
HttpContext.Current.Response.Write(resdata /*your desired output to the client*/);