I write a temp http protocol according to http://www.codeproject.com/KB/aspnet/AspxProtocol.aspx?display=PrintAll and the Code is as follow,
public void Start(string szURL, IInternetProtocolSink Sink, IInternetBindInfo pOIBindInfo, uint grfPI, uint dwReserved)
{
try
{
IServiceProvider Provider = (IServiceProvider)Sink;
object obj_Negotiate = new object();
Provider.QueryService(ref Guids.IID_IHttpNegotiate, ref Guids.IID_IHttpNegotiate, out obj_Negotiate);
IHttpNegotiate Negotiate = (IHttpNegotiate)obj_Negotiate;
string strRequestHeaders;
Negotiate.BeginningTransaction(szURL, string.Empty, 0, out strRequestHeaders);
BINDINFO BindInfo = GetBindInfo(pOIBindInfo);
String RawPostData = GetPostData(BindInfo, szURL);
HttpWebResponse HttpResp = GetHttpWebResponse(szURL, RawPostData, strRequestHeaders);
uint RespCode = (uint)HttpResp.StatusCode;
using (Stream RespStream = HttpResp.GetResponseStream())
{
byte[] rgb = new byte[1024];
int cb;
while ((cb = RespStream.Read(rgb, 0, rgb.Length)) > 0)
{
MemStream.Write(rgb, 0, cb);
}
}
MemStream.Position = 0;
String ContentType = HttpResp.GetResponseHeader("Content-Type");
string StrResponseHeaders = HttpResp.Headers.ToString();
string strNewResponseHeaders;
Negotiate.OnResponse(RespCode, StrResponseHeaders, strRequestHeaders, out strNewResponseHeaders);
Sink.ReportData(BSCF.BSCF_FIRSTDATANOTIFICATION | BSCF.BSCF_LASTDATANOTIFICATION | BSCF.BSCF_DATAFULLYAVAILABLE, (uint)MemStream.Length, (uint)MemStream.Length);
if (!String.IsNullOrEmpty(ContentType))
{
Sink.ReportProgress((uint)BINDSTATUS.BINDSTATUS_MIMETYPEAVAILABLE, ContentType);
}
Sink.ReportResult(0, 0, null);
HttpResp.Close();
}
catch (Exception e)
{
Debug.WriteLine(e.ToString());
}
}
it works well for web pages navigating, but the WebBrowser and the winform hangs when waiting for a slow asynchronous pluggable protocol response . such as the target file sleep.php :
<?php
sleep(10);
print_r("Sleep Test\n");
?>
The winform will not reponse any mouse click within 10 seconds. How to resolve it (let the winform response the mouse click when pluggable protocol is in progress) ? Thank you.
Envrionment: .Net 2.0, VS2008, C#, WinForm, WebBrowser Control