e语言 读取http 不运行html,HttpErrorResponse-无法从服务器获取文本/ html响应

我在从服务器获取http响应时遇到问题。

我想将HttpClient的身份验证登录复制到我的login.service.ts文件中。

我在最后几个小时尝试了2个解决方案,但没有任何帮助...

这是我使用的代码:

login.service.ts

import { Injectable } from '@angular/core';

import { HttpClient } from '@angular/common/http';

@Injectable({

providedIn: 'root'

})

export class LoginService {

constructor(private http: HttpClient) { }

login(){

this.http.post('http://localhost:3000/auth', null, {headers: {

'x-login': 'admin',

'x-password': '8c6976e5b5410415bde908bd4dee15dfb167a9c873fc4bb8a81f6f2ab448a918'}})

.subscribe(myToken => console.log(myToken));

}

}

我使用PostMan测试登录名和密码,/ auth响应令牌:653db89e-b80e-47f8-834a-62275b04fcbb。

Content-Type不是JSON响应,这是text / html; charset = utf-8,我认为可能是问题所在,但我真的不知道。

错误是:

HttpErrorResponse {headers: HttpHeaders, status: 201, statusText: "Created", url: "http://localhost:3000/auth", ok: false, …}

error: {error: SyntaxError: Unexpected number in JSON at position 1 at JSON.parse () at XMLHttp…, text: "08951337-479a-4e53-8b1b-823d29d89139"}

headers: HttpHeaders {normalizedNames: Map(0), lazyUpdate: null, lazyInit: ƒ}

message: "Http failure during parsing for http://localhost:3000/auth"

name: "HttpErrorResponse"

ok: false

status: 201

statusText: "Created"

url: "http://localhost:3000/auth"

__proto__: HttpResponseBase

欢迎任何帮助!

如果我说的不清楚,我会尝试学习Angular 7,

请随时询问我更多信息。

谢谢!

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值