Ignore request body for XHR GET requests.

Raises an error on Android. Caused by the Angular XHR backend sending an
empty string.
This commit is contained in:
Hristo Deshev
2015-10-17 19:04:00 +03:00
parent 2f92cb3ff4
commit 75796ea14c
2 changed files with 12 additions and 1 deletions

View File

@@ -212,6 +212,14 @@ export var test_XMLHttpRequest_requestShouldBePossibleAfterAbort = function (don
xhr.send(JSON.stringify({ MyVariableOne: "ValueOne", MyVariableTwo: "ValueTwo" }));
};
export function test_ignore_zero_length_request_body(done) {
let xhr = new XMLHttpRequest();
xhr.open("GET", "https://httpbin.org/get");
xhr.send('');
done(null);
}
export function test_raises_onload_Event(done) {
let xhr = new XMLHttpRequest();
xhr.onload = () => {

View File

@@ -72,7 +72,10 @@ export class XMLHttpRequest {
this._status = null;
if (types.isDefined(this._options)) {
if (types.isString(data)) {
if (types.isString(data) && this._options.method !== 'GET') {
//The Android Java HTTP lib throws an exception if we provide a
//a request body for GET requests, so we avoid doing that.
//Browser implementations silently ignore it as well.
this._options.content = data;
} else if (data instanceof FormData) {
this._options.content = (<FormData>data).toString();