WebKit.Net, since version 0.3.0, it seems that it does not have access to the code form. I did something a little different, I used WebKit.Net, but I added an HTTP listener to the application, and I configured the control to fetch pages from there. This way, I have access to messages and callbacks in one application. Otherwise, I am doing this with JavaScript on my page.
HttpListener listener;
public Form1( ) {
InitializeComponent( );
listener = new System.Net.HttpListener( );
listener.Prefixes.Add( "http://*:88/" );
listener.Start( );
IAsyncResult result = listener.BeginGetContext( new AsyncCallback( ListenerCallback ), listener );
}
public static void ListenerCallback( IAsyncResult result ) {
string resp = "<body>test</body";
HttpListener listener = ( HttpListener )result.AsyncState;
try {
HttpListenerContext context = listener.EndGetContext( result );
HttpListenerRequest request = context.Request;
HttpListenerResponse response = context.Response;
string webpage = request.Url.AbsolutePath.Substring( 1 );
string responseString = null;
if ( string.IsNullOrEmpty( webpage ) ) {
responseString = resp;
}
else {
webpage = webpage.Replace( ".", "_" );
responseString = webkit_test.Properties.Resources.ResourceManager.GetResourceSet( System.Globalization.CultureInfo.CurrentCulture, true, false ).GetObject( webpage ) as string;
if ( responseString == null ) {
responseString = "<html></html><body> 404 Web Page not Found</body>";
}
}
byte[ ] buffer = System.Text.Encoding.UTF8.GetBytes( responseString );
response.ContentType = "text/html; charset=UTF-8";
response.ContentLength64 = buffer.Length;
System.IO.Stream output = response.OutputStream;
output.Write( buffer, 0, buffer.Length );
output.Flush( );
output.Close( );
IAsyncResult result1 = listener.BeginGetContext( new AsyncCallback( ListenerCallback ), listener );
}
catch { }
}
Btw. This code will also read the web page from the entered resource.
source
share