Add Content-Type header in HttpClient.ts (#2242)
This commit is contained in:
parent
2388dd3a76
commit
cd8f238f83
|
|
@ -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)
|
||||
|
|
|
|||
Loading…
Reference in New Issue