【发布时间】:2019-04-03 17:53:48
【问题描述】:
我对此感到非常疯狂,我几乎尝试了所有方法,但找不到将字符串值从服务传递到后端以根据该字符串返回 Json 结果的方法。
这就是问题所在,我有一个使用元信息来处理所有 JSON 的后端 前端提供,然后将它们返回到前端进行显示,在这种情况下,我必须获取一个基于过滤器的 JSON,该过滤器由插入前端的字符串制成,但找不到将字符串传递给后端的方法,我不想通过 URL 传递它。
这是我的代码:
angular typescript 服务:我想通过"whr"
getAdvancedFilterResult(concept: string, whr: string): Promise<any> {
const headers: Headers = new Headers({
'Content-Type': 'application/json'
});
this.authService.getAuthorizationHeader(headers);
headers.append('IdLng', this.config.idLanguage);
const options: RequestOptions = new RequestOptions();
options.headers = headers;
return this.http.get(this.config.apiDomain + this.config.apiEndpointEntities + '/' + concept + '/' + "filtered",
options
)
.toPromise()
.then(
response => response.json() as any[]
)
.catch((error) => this.customHandleError(error, this.toastrService));
}
后端控制器:
[Route("api/Entities/{entity}/filtered/")]
public HttpResponseMessage GetFilter(string entity) {
HttpResponseMessage response = new HttpResponseMessage();
string action = "READ";
//Check Authorization
AuthorizationResponse authResponse = AuthProvider.CheckAuthorization(new AuthorizationRequest() {
SCode = UserUtils.GetUserSCode(User),
ConceptString = entity,
ActionString = action,
UserId = UserUtils.GetUserID(User),
ExtraParameters = new AuthorizationRequest.ExtraParamaters() {
IdsOnly = false, Where = "!!!!!WHR HERE!!!!"
}
});
if (authResponse.IsAuthorized) {
//code
response = Request.CreateResponse(HttpStatusCode.OK, json);
} else {
response = Request.CreateResponse(HttpStatusCode.Unauthorized);
}
return response;
}
我应该通过header 和headers.append('whr', whr); 将它传递到http.get 上的options 还是通过options.body = whr; 进入body?
另外,我怎样才能让它在后端使用?
【问题讨论】:
标签: c# angular typescript