0
이 앱이 서버에서 웹 브라우저로 수신하는 html 문자열을 표시하려고합니다. 웬일인지 나는 비참하게 실패하고있다. html 문자열을 메시지 상자에 표시 할 수 있지만 웹 브라우저에 표시 할 수 없습니다. 나는 C#에 익숙하지 않아 불필요한 코드 나 실수를 사과한다. 또한 미리 감사드립니다.웹 브라우저에 html 문자열 표시
namespace Test2
{
public partial class MainPage : PhoneApplicationPage
{
private static readonly Dispatcher Dispatcher;
// Constructor
public MainPage()
{
InitializeComponent();
}
private void button1_Click(object sender, RoutedEventArgs e)
{
// Create a new HttpWebRequest object.
HttpWebRequest request = (HttpWebRequest)WebRequest.Create("http://127.0.0.1/examples/servlets/servlet/ReverseServlet");
request.ContentType = "application/x-www-form-urlencoded";
// Set the Method property to 'POST' to post data to the URI.
request.Method = "POST";
// start the asynchronous operation
request.BeginGetRequestStream(new AsyncCallback(GetRequestStreamCallback), request);
}
private static void GetRequestStreamCallback(IAsyncResult asynchronousResult)
{
HttpWebRequest request = (HttpWebRequest)asynchronousResult.AsyncState;
// End the operation
Stream postStream = request.EndGetRequestStream(asynchronousResult);
System.Diagnostics.Debug.WriteLine("Please enter the input data to be posted:");//Test code
string postData = "string is this = Testing out this app for windows 7 phone";// Test string added
// Convert the string into a byte array.
byte[] byteArray = Encoding.UTF8.GetBytes(postData);
// Write to the request stream.
postStream.Write(byteArray, 0, postData.Length);
postStream.Close();
// Start the asynchronous operation to get the response
request.BeginGetResponse(new AsyncCallback(GetResponseCallback), request);
}
private static void GetResponseCallback(IAsyncResult asynchronousResult)
{
Deployment.Current.Dispatcher.BeginInvoke(
() =>
{
HttpWebRequest request = (HttpWebRequest)asynchronousResult.AsyncState;
// End the operation
HttpWebResponse response = (HttpWebResponse)request.EndGetResponse(asynchronousResult);
Stream streamResponse = response.GetResponseStream();
StreamReader streamRead = new StreamReader(streamResponse);
string responseString = streamRead.ReadToEnd();
WebBrowser webBrowser1 = new WebBrowser();
MessageBox.Show(responseString);//Message box displays html
webBrowser1.Visibility = Visibility.Visible;
webBrowser1.NavigateToString(responseString);//Does NOT display html string
System.Diagnostics.Debug.WriteLine(responseString+" FIXED IT");
// Close the stream object
streamResponse.Close();
streamRead.Close();
// Release the HttpWebResponse
response.Close();
//allDone.Set();
});
}
}
}
webBrowser1.DocumentText = responseString; ? 또는 webBrowser 컨트롤이 WPF 폼의 winForm에도 없습니다. – tschmit007