Skip to content
代码片段 群组 项目
未验证 提交 5d37d312 编辑于 作者: Andrew Stanton-Nurse's avatar Andrew Stanton-Nurse 提交者: GitHub
浏览文件

Add Content-Type header in HttpClient.ts (#2242) (#2413)

上级 c976d0aa
No related branches found
No related tags found
无相关合并请求
......@@ -83,5 +83,10 @@ namespace FunctionalTests
String = "hello world",
};
}
public string GetContentTypeHeader()
{
return Context.GetHttpContext().Request.Headers["Content-Type"];
}
}
}
......@@ -686,6 +686,24 @@ describe("hubConnection", () => {
}
});
it("populates the Content-Type header when sending XMLHttpRequest", async (done) => {
const hubConnection = getConnectionBuilder(HttpTransportType.LongPolling, TESTHUB_NOWEBSOCKETS_ENDPOINT_URL)
.withHubProtocol(new JsonHubProtocol())
.build();
try {
await hubConnection.start();
// Check what transport was used by asking the server to tell us.
expect(await hubConnection.invoke("GetActiveTransportName")).toEqual("LongPolling");
// Check to see that the Content-Type header is set the expected value
expect(await hubConnection.invoke("GetContentTypeHeader")).toEqual("text/plain;charset=UTF-8");
done();
} catch (e) {
fail(e);
}
});
function getJwtToken(url: string): Promise<string> {
return new Promise((resolve, reject) => {
const xhr = new XMLHttpRequest();
......
......@@ -163,6 +163,8 @@ export class DefaultHttpClient extends HttpClient {
xhr.open(request.method, request.url, true);
xhr.withCredentials = true;
xhr.setRequestHeader("X-Requested-With", "XMLHttpRequest");
// Explicitly setting the Content-Type header for React Native on Android platform.
xhr.setRequestHeader("Content-Type", "text/plain;charset=UTF-8");
if (request.headers) {
Object.keys(request.headers)
......
0% 加载中 .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册