Hi
I have ran into this problem recently, which xhr.getResponseHeader(“Set-Cookie”) did not receive complete header message and happened in POST request in cocos simulator on Windows only.
Furthermore, xhr.getResponseHeader(“Set-Cookie”) of a POST request worked fine under iOS and Android , but not under cocos simulator on Windows.
I wonder if this is a bug of cocos simulator?
Any help is appreciated.
你好,
最近我们用Cocos creator 开发, 遇到一个问题.
在cocos 的模拟器在windows 上, 我们用xmlHttpRequest POST 请求, 然後xhr.getResponseHeader(“Set-Cookie”) 取回来的header, 里面的信息不完整, 但如果是用GET 却没此问题.
如果在iOS 和 Android 也不会有缺少cookie资讯的问题,
我想请问这是 cocos模拟器的bug 还是什麽问题?
谢谢
Here is a piece of my code:
let COOKIE = “”;
private static makeRequest(method: string, url: string, done: { (response: string): void }, fail: { (state:
number): void }, params:string) {
let xhr = new XMLHttpRequest();
xhr.onreadystatechange = function() {
if (xhr.readyState == 4 && xhr.status >= 200 && xhr.status < 400) {
COOKIE = xhr.getResponseHeader("Set-Cookie");
done(xhr.responseText);
} else if (xhr.status != 0) {
fail(xhr.status);
}
};
xhr.open(method, url, true);
if (method === "POST") {
xhr.setRequestHeader("Content-type", "application/x-www-form-urlencoded; charset=utf-8");
xhr.setRequestHeader("Accept", "application/json, text/javascript, */*; q=0.01");
}
xhr.setRequestHeader("Cookie", COOKIE);
xhr.withCredentials = true;
xhr.timeout = 120 * 1000;
if(method == "POST")
xhr.send(params);
else
xhr.send();
}