【发布时间】:2021-12-12 09:25:35
【问题描述】:
这是请求正文的 Postman 示例 我将 query_string 发送到烧瓶后端,它返回推文列表。
现在我想使用 http 客户端 post 方法从 Angular 应用程序发送 post 请求
searchTerm 是查询字符串
import { GoogleResponse } from './components/GoogleResponse.model';
import { environment } from './../environments/environment';
import { Injectable, Query } from '@angular/core';
import { HttpClient } from '@angular/common/http';
import { Observable } from 'rxjs';
import { solr_Response } from './components/solr_response.model';
@Injectable({
providedIn: 'root'
})
export class SearchService {
private url: string = '3.22.175.82:5000/queryresult';
/* solr url */
constructor(private httpClient:HttpClient) { }
/**
*
* @param searchTerm
* @returns
*/
getSearchData(searchTerm: string): Observable<any> {
return this.httpClient.post(this.url, searchTerm);
}
}
我只是发送一个字符串作为请求正文,但它给了我错误我的猜测是正文需要在一个对象中,或者简单的字符串就足够了。 但我收到了这个错误
【问题讨论】:
-
网址不应该以 http:// 或 https:// 开头吗?
-
在您的错误响应中,url 字段显示的 URL 不正确。
标签: angular