Angular Internet explorer 11和HttpClient post的polyfills问题

Angular Internet explorer 11和HttpClient post的polyfills问题,angular,typescript,httpclient,internet-explorer-11,polyfills,Angular,Typescript,Httpclient,Internet Explorer 11,Polyfills,我很难让angular 4应用程序在IE11中使用新的httpclient帖子。这个问题只与IE11有关,在chrome中运行良好 我一直收到无效字符的错误消息。 从我所看到的不同之处是我发送到服务器的帖子正文。在chrome浏览器中,其格式如下: 在IE11中,相同的对象是这样的: 这些符号属性是否会弄乱对象,使其无法在服务器上被接受?如果我不使用截取器解析错误消息,我只会得到内部服务器错误(500) 这是我指定在正文中发送的对象: 让body={ FromDate:form.fromD

我很难让angular 4应用程序在IE11中使用新的httpclient帖子。这个问题只与IE11有关,在chrome中运行良好

我一直收到无效字符的错误消息。

从我所看到的不同之处是我发送到服务器的帖子正文。在chrome浏览器中,其格式如下:

在IE11中,相同的对象是这样的:

这些符号属性是否会弄乱对象,使其无法在服务器上被接受?如果我不使用截取器解析错误消息,我只会得到内部服务器错误(500)

这是我指定在正文中发送的对象:

让body=
{
FromDate:form.fromDepDate,//日期
ToDate:form.toDepDate,//日期
userid:userid//字符串数组

};

我不能100%肯定我理解你的要求。这看起来像是许多angular用户在IE上遇到的问题。这个问题是http请求实际上通过了,但angular将其视为错误,因为它无法解析服务器响应(但您谈论的是500个?如果您实际收到500个内部服务器错误,则很可能是后端出现了问题)

如果你没有得到500分,但行为很糟糕,如上所述,这似乎是IE11(可能还有其他)上angular 4+的一个bug。看起来HttpClient无法解析空的200个响应

该漏洞被跟踪到服务器上

尽管它在angular 5.2.4中得到了修复,但如果您不能或不想更新,多个解决方案似乎都可以:

  • 一种可能性是,当响应正文为空时,将服务器更改为返回
    204 No Content
    ,而不是返回200
  • 另一种可能的解决方法是使用HTTP拦截器来完成这项工作
这是我的解决方案:

@Injectable()
export class EmptyResponseBodyInterceptor implements HttpInterceptor {
intercept(req: HttpRequest < any > , next: HttpHandler): Observable < HttpEvent < any >> {
    req = req.clone({
        responseType: 'text'
    });

    return next.handle(req)
        .map((res) => {
            if (res instanceof HttpResponse) {
                if (res.body === 'OK') {
                    res.clone({
                        body: null
                    });
                } else {
                    res = res.clone < any > ({
                        body: res.body !== '' ? JSON.parse(res.body) : null
                    });
                }
            }

            return res;
        });
}
@Injectable()
导出类EmptyResponseBodyInterceptor实现HttpInterceptor{
截取(req:HttpRequest,next:HttpHandler):可观察的>{
req=req.clone({
响应类型:“文本”
});
返回下一个句柄(req)
.map((res)=>{
if(HttpResponse的res instanceof){
如果(res.body==='OK'){
克隆研究({
正文:空
});
}否则{
res=res.clone({
body:res.body!=''?JSON.parse(res.body):null
});
}
}
返回res;
});
}

}我不能100%肯定我理解你的要求。这看起来像是许多angular用户在IE上遇到的问题。这个问题是http请求实际上通过了,但angular将其视为错误,因为它无法解析服务器响应(但您谈论的是500个?如果您实际收到500个内部服务器错误,则很可能是后端出现了问题)

如果你没有得到500分,但行为很糟糕,如上所述,这似乎是IE11(可能还有其他)上angular 4+的一个bug。看起来HttpClient无法解析空的200个响应

该漏洞被跟踪到服务器上

尽管它在angular 5.2.4中得到了修复,但如果您不能或不想更新,多个解决方案似乎都可以:

  • 一种可能性是,当响应正文为空时,将服务器更改为返回
    204 No Content
    ,而不是返回200
  • 另一种可能的解决方法是使用HTTP拦截器来完成这项工作
这是我的解决方案:

@Injectable()
export class EmptyResponseBodyInterceptor implements HttpInterceptor {
intercept(req: HttpRequest < any > , next: HttpHandler): Observable < HttpEvent < any >> {
    req = req.clone({
        responseType: 'text'
    });

    return next.handle(req)
        .map((res) => {
            if (res instanceof HttpResponse) {
                if (res.body === 'OK') {
                    res.clone({
                        body: null
                    });
                } else {
                    res = res.clone < any > ({
                        body: res.body !== '' ? JSON.parse(res.body) : null
                    });
                }
            }

            return res;
        });
}
@Injectable()
导出类EmptyResponseBodyInterceptor实现HttpInterceptor{
截取(req:HttpRequest,next:HttpHandler):可观察的>{
req=req.clone({
响应类型:“文本”
});
返回下一个句柄(req)
.map((res)=>{
if(HttpResponse的res instanceof){
如果(res.body==='OK'){
克隆研究({
正文:空
});
}否则{
res=res.clone({
body:res.body!=''?JSON.parse(res.body):null
});
}
}
返回res;
});
}

}

你修好了吗?我也有同样的问题你修好了吗?我也有同样的问题