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

This commit is contained in:
Brian Mortensen 2018-05-16 15:31:39 -07:00 committed by James Newton-King
parent 2388dd3a76
commit cd8f238f83
3 changed files with 25 additions and 0 deletions

View File

@ -83,5 +83,10 @@ namespace FunctionalTests
String = "hello world",
};
}
public string GetContentTypeHeader()
{
return Context.GetHttpContext().Request.Headers["Content-Type"];
}
}
}

View File

@ -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();

View File

@ -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)