我有一个奇怪的问题。 我的日志显示,由于标头对象为空,因此发布端点有时返回http 400。似乎是有问题的同一用户。
我无法在本地重现该问题,并且终结点计算机在大多数情况下对于大多数用户都有效。
export async function postJson<T>(
url: string,
jsonPayload: string,
caller: string
) {
const headers = new Headers();
headers.append("Content-Type", "application/json");
const payload: RequestInit = {
credentials: "same-origin",
method: "post",
headers: headers,
body: jsonPayload
};
const response = await fetch(url, payload);
if (response.ok) {
//Testing for empty response
const data = await response.text();
if (data) {
return <T>JSON.parse(data);
} else {
return null;
}
} else {
throw new Error(
`Url=${url} returned non-ok status: ${response.status}. Status text:${
response.statusText
}; caller=${caller}, payload=${JSON.stringify(payload)}`
);
}
}
日志显示有效负载对象为
payload={"credentials":"same-origin","method":"post","headers":{},"body":"...some json..."}
获得400的用户代理是
Mozilla/5.0 (Windows NT 6.3; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/75.0.3770.100 Safari/537.36
有什么想法吗?