(原因:缺少 CORS 标头'Access-Control-Allow-Origin')API 问题


import { Injectable } from '@angular/core';
import { HttpClient} from '@angular/common/http';
import { Movie } from './movie.model';

@Injectable({
providedIn: 'root'
})
export class MoviesService {
searchMovie(title: String)
{
const url = 'https://www.omdbapi.com/?t='+title+'&apikey=******';

return this.httpClient.get(url);

}
saveMovie(movie:Movie)
{
return this.httpClient.post<Movie>('http://localhost:2222/movie',movie);
}
dbmovie(movie:Movie)
{
return this.httpClient.post<Movie>('http://localhost:2222/movie/main',movie);
}

getAll(email:String){
return this.httpClient.get<Movie[]>(`http://localhost:2222/movie/fav/${email}`);
}
getallDetailes(){
return this.httpClient.get<Movie[]>(`http://localhost:2222/movie/foradmin`);
}
delete(title:String,email:String){
return this.httpClient.delete<Movie >(`http://localhost:2222/movie/${title}/${email}`);
}
deleteAdminMovie(title:String){
return this.httpClient.delete<Movie >(`http://localhost:2222/movie/admin/${title}`);
}
getTitle(){
return this.httpClient.get<Movie[]>(`http://localhost:2222/movie/`);
}
constructor(private httpClient: HttpClient) {}
}

在大多数情况下,这将是后端产生的问题。

BE未配置允许FE端口号。

相关内容

最新更新