After I load a url with the browser, I'm sending a request follows:
var frame = browser.GetMainFrame();
var request = frame.CreateRequest();
request.Url = "urlhere";
request.Method = "PUT";
NameValueCollection headers = new NameValueCollection();
headers.Add("Host", "hosthere");
//etc...
request.Headers = headers
request.InitializePostData();
var element = request.PostData.CreatePostDataElement();
element.Bytes = Encoding.UTF8.GetBytes("mydata") ;
request.PostData.AddElement(element);
frame.LoadRequest(request);
However I get the error:
{"message":"Invalid Cookie", "code":482}
CefSharp is initialized as follows:
CefSettings settings = new CefSettings();
settings.CefCommandLineArgs.Add("enable-npapi", "1");
Cef.Initialize(settings);
I also have multiple browsers, which are created as follows:
var contextSettings = new RequestContextSettings();
contextSettings.CachePath = cachePath;
var browser = new ChromiumWebBrowser(urlStr)
{
BrowserSettings = new BrowserSettings()
{
Javascript = CefState.Enabled,
Plugins = CefState.Enabled,
},
RequestContext = new RequestContext(contextSettings),
RequestHandler = new CustomRequestHandler,
};
As shown in the snippet above, I'm using a cache path for each browser session. Wouldn't the cookies be located there?
How do I retrieve the cookies and set them for this request?
Also, I'm not setting the Content-Length
header. Is this set by cefSharp
automatically when sending a Post request?
EDIT
To get the cookies I'm doing:
var cookies = await Cef.GetGlobalCookieManager().VisitAllCookiesAsync();
However the list always contains 0 cookies.
I've also cleared the cache, and once the page was loaded, I noticed that a Cookies
file was created. Editing it (looks like a SQLite3 database) shows that cookies have been actually created and there are those that I'm interesed in.
So why isn't the manager getting the cookies?