本帖最后由 cgbsmy 于 2022-11-17 21:17 编辑
1.复制cookie时要选择复制而不能直接复制值,因为有字符要转义
2.你们复制的时候都是没有带domain,所以在使用cookie时签到不能用,比如52pj
3.为什么有些论坛想退出账号不行,因为恢复cookie时,bbs.级无法访问到www.级,同第2点
4.京东或淘宝一下子过期的,可以把备份的再恢复cookie刷新页面,马上又可以使用了
[C++] 纯文本查看 复制代码 void SetCookie(LPCWSTR uri, LPWSTR lpCookie)
{
if (webviewWindow2)
{
if (cookieManager)
{
// cookieManager->DeleteAllCookies();
LPWSTR cStart = lpCookie;
while (cStart)
{
LPWSTR cValue = lstrstr(cStart, L"=");
if (cValue > cStart && cValue != NULL)
{
cValue[0] = L'\0';
LPWSTR cName = cStart;
cValue += 1;
cStart = lstrstr(cValue, L"; ");
if (cStart != NULL)
{
cStart[0] = L'\0';
cStart += 2;
}
LPWSTR cUri = lstrstr(cValue, L" ");
if (cUri)
{
cUri[0] = L'\0';
cUri += 1;
}
wil::com_ptr<ICoreWebView2Cookie> cookie;
if(cUri)
cookieManager->CreateCookie(cName, cValue, cUri, L"/", &cookie);
else
cookieManager->CreateCookie(cName, cValue, uri, L"/", &cookie);
cookieManager->AddOrUpdateCookie(cookie.get());
}
else
cStart = NULL;
}
}
}
}
void ViewCookie(LPWSTR wUri)
{
std::wstring uri = wUri;
HWND hWnd = hWeb;
if (cookieManager)
{
cookieManager->GetCookies(uri.c_str(),
Callback<ICoreWebView2GetCookiesCompletedHandler>(
[hWnd, uri](HRESULT error_code, ICoreWebView2CookieList* list) -> HRESULT {
std::wstring result,result1;
UINT cookie_list_size;
list->get_Count(&cookie_list_size);
if (cookie_list_size == 0)
{
result += L"No cookies found.";
}
else
{
result = L"<input type='button' id='copy' onclick=document.getElementById('cookie').select();document.execCommand('copy');alert('已复制'); value='复制' /><textarea id='cookie' style='width:100%;height:39%;'>";
result1 = L"<input type='button' id='copy' onclick=document.getElementById('domain').select();document.execCommand('copy');alert('已复制'); value='复制带Domain' /><textarea id='domain' style='width:100%;height:55%;'>";
for (UINT i = 0; i < cookie_list_size; ++i)
{
wil::com_ptr<ICoreWebView2Cookie> cookie;
list->GetValueAtIndex(i, &cookie);
if (cookie.get())
{
wil::unique_cotaskmem_string domain;
cookie->get_Domain(&domain);
wil::unique_cotaskmem_string name;
cookie->get_Name(&name);
wil::unique_cotaskmem_string value;
cookie->get_Value(&value);
result += name.get();
result += L"=";
result += value.get();
result1 += name.get();
result1 += L"=";
result1 += value.get();
result1 += L" ";
result1 += domain.get();
if (i != cookie_list_size - 1)
{
result += L"; ";
result1 += L"; ";
}
}
}
result += L"</textarea><br/>";
result1 += L"</textarea>";
result += result1;
webviewWindow3->NavigateToString(result.c_str());
}
return S_OK;
})
.Get());
}
} |