アプリケーションをテストするために Visual Studio .net core 5 Angular テンプレートを試しています。book エンティティを使用して CRUD 機能を追加しました
public class Book
{
[Key]
public int BookId { get; set; }
[Column(TypeName = "nvarchar(40)")]
public string Titulo { get; set; }
[Column(TypeName = "nvarchar(40)")]
public string Autor { get; set; }
[Column(TypeName = "nvarchar(40)")]
public string Editorial { get; set; }
}
Visual Studio 2019 でこのサイトを実行すると、iis Express の両方の API 実行権限があり、正しく返されますが、IIS 10 または Windows Azure で公開するとエラーが返されます。
"ERROR Error: Uncaught (in promise): n: {"headers":{"normalizedNames":{},"lazyUpdate":null},"status":200,"statusText":"OK","url":"http://localhost:8090/api/Books","ok":false,"name":"HttpErrorResponse","message":"Http failure during parsing for http://localhost:8090/api/Books","error":{"error":{"description":"Carácter no válido","number":-2146827274,"stack":"SyntaxError: Carácter no válido\n "
ブック API 呼び出し用。json 解析エラーのように見えますが、このエラーを生成する可能性のある特殊文字がありません。この Web サイトはhttps://bookswebapiang.azurewebsites.net/で公開されています。 これは API から json を返すコードですが、エラーが発生する理由がわかりません。
import {Injectable } from '@angular/core';
import { Book } from './book.model';
import { HttpClient} from "@angular/common/http";
@Injectable({
providedIn: 'root'
})
export class BookService {
constructor(private http: HttpClient) { }
readonly baseURL = 'http://localhost:8090/api/Books'
formData: Book = new Book();
list: Book[];
postBook() {
return this.http.post(this.baseURL, this.formData);
}
putBook() {
return this.http.put(`${this.baseURL}/${this.formData.bookId}`, this.formData);
}
deleteBook(id: number) {
return this.http.delete(`${this.baseURL}/${id}`);
}
refreshList() {
this.http.get(this.baseURL)
.toPromise()
.then(res => this.list = res as Book[]);
}
//refreshList() {
// this.http.get<Book[]>(this.baseURL).subscribe(result => {
// this.list = result;
// }, error => console.error(error));
//}
}