This is how I send the request:
- Code: Select all
function sendRequest(data) {
var xhr = new XMLHttpRequest();
xhr.open("POST", "http://request", false);
xhr.setRequestHeader("Content-type", "application/x-www-form-urlencoded; charset=utf-8");
xhr.onload = function (e) {
if (xhr.readyState === 4) {
if (xhr.status === 200) {
console.log(xhr.responseText);
} else {
console.error(xhr.statusText);
}
}
};
xhr.onerror = function (e) {
console.error(xhr.statusText);
};
xhr.send(data);
}
sendRequest('data=somethingöü߶m2=lsdjf');
And this is how I try to red that request in CEF3:
- Code: Select all
CefRefPtr<CefPostData> postData = request->GetPostData();
if (postData != NULL) {
CefPostData::ElementVector elements;
postData->GetElements(elements);
if (elements.size() > 0) {
std::wstring queryString;
// it looks like the whole query string is in this first post data element?
CefRefPtr<CefPostDataElement> query = elements[0];
if (query->GetType() == PDE_TYPE_BYTES) {
wchar_t *buff = new wchar_t[query->GetBytesCount() + 1];
query->GetBytes(query->GetBytesCount(), buff); // buff contains a string which is not correctly utf8 encoded.
// this is how it looks like: 慤慴猽浯瑥楨杮뛃볃鿃瀦牡浡㴲獬橤쵦췍
// if I cast it to (char*) it looks like: data=somethingöü߶m2=lsdjf
queryString = std::wstring(buff, query->GetBytesCount());
delete[] buff;
}
}
}
I could not find any example for this. Any help is much appreciated.