class DumpRequestResourceHandler : CefResourceHandler
{
private static int _requestNo;
private byte[] responseData;
private int pos;
protected override void GetResponseHeaders(CefResponse response, out long responseLength, out string redirectUrl)
{
response.Status = 200;
response.MimeType = "text/html";
response.StatusText = "OK, hello from handler!";
var headers = new NameValueCollection(StringComparer.InvariantCultureIgnoreCase);
headers.Add("Cache-Control", "private");
headers.Add("Access-Control-Allow-Origin", "*");
response.SetHeaderMap(headers);
responseLength = responseData=https://bbs.csdn.net/topics/=null?0:responseData.Length;
redirectUrl = null;
}
protected override bool Open(CefRequest request, out bool handleRequest, CefCallback callback)
{
Thread thread = new Thread(() =>
{
var response = new StringBuilder();
try
{
var requestNo = Interlocked.Increment(ref _requestNo);
string[] para;
if (request.PostData != null)
{
para = HttpUtility.UrlDecode(Encoding.UTF8.GetString(request.PostData.GetElements()[0].GetBytes())).Split('&');
}
else
{
var pl = HttpUtility.UrlDecode(request.Url).Split('&');
para = new string[pl.Length - 1];
for (int i = 1; i < pl.Length; i++)
{
para[i - 1] = pl[i];
}
}
response.Append("Testing!!!");
}
catch (Exception ex)
{
response.Append(ex.Message + ex.StackTrace);
}
finally {
responseData = Encoding.UTF8.GetBytes(response.ToString());
callback.Continue();
}
});
thread.Start();
handleRequest = true;
return true;
}
protected override bool Read(IntPtr dataOut, int bytesToRead, out int bytesRead, CefResourceReadCallback callback)
{
var dataLen = responseData == null ? 0 : responseData.Length;
if (bytesToRead == 0 || pos >= dataLen)
{
bytesRead = 0;
return false;
}
else
{
pos += bytesToRead;
bytesRead = bytesToRead;
dataOut = (IntPtr)pos;
return true;
}
}
protected override bool Skip(long bytesToSkip, out long bytesSkipped, CefResourceSkipCallback callback)
{
bytesSkipped = bytesToSkip;
return false;
}
protected override void Cancel()
{
}
}
這個是版本資料
internal static unsafe partial class libcef
{
public const string CEF_VERSION = "88.2.9+g5c8711a+chromium-88.0.4324.182";
public const int CEF_VERSION_MAJOR = 88;
public const int CEF_COMMIT_NUMBER = 2301;
public const string CEF_COMMIT_HASH = "5c8711aa6017c48688dd03915062bd5f9382ee3e";
public const int CHROME_VERSION_MAJOR = 88;
public const int CHROME_VERSION_MINOR = 2;
public const int CHROME_VERSION_BUILD = 4324;
public const int CHROME_VERSION_PATCH = 182;
public const string CEF_API_HASH_UNIVERSAL = "89715b43c948313782d2546131f510eab1975844";
public const string CEF_API_HASH_PLATFORM_WIN = "80648a2c5a87db1581fdb994b7154ed77d74a3c5";
public const string CEF_API_HASH_PLATFORM_MACOS = "3af393a2bf165edd934c5a59f6e6fce8a4bb579c";
public const string CEF_API_HASH_PLATFORM_LINUX = "8049cab9a43c1d554ccdd4dd3d5e38ecebce42af";
}
這個是實作該類的完整代碼,我現在遇到的問題是:如何回傳資料給呼叫者。
轉載請註明出處,本文鏈接:https://www.uj5u.com/net/264979.html
標籤:ASP.NET
