[英]Angular4+ and Asp.NET Core with a redirect response
我有一个ASP.NET Core Api,在Controller中有一个Post方法,并且有一个对其进行调用的角度服务。直到今天,我在路由器的角度范围内进行导航,但是我需要知道它是否可行以及如何从该角度重定向服务器并通过有角度的Post方法处理这种情况,该方法将接收重定向响应而不是一些JSON对象。 浏览器可以单独处理吗,还是我在收到响应后需要在通话中做些事情?
客户端和服务器在同一服务器上运行
控制者
[HttpPost]
public ActionResult Post([FromBody]string myvalue)
{
// some operations here
string parameter = SomeFunctionReturningParameter(myvalue);
return new RedirectResult("/component2?param=" + parameter);
}
}
角度服务
public callRedirection(apiEnd:, body: any): Observable<any> {
return this.http.post(endPoint, body)
.map((response) => {
//how to handle redirect here
return response;
})
.catch(error => { console.log(error) });
}
任何想法???
您应该能够将Router导入到您的组件中,并在处理程序中提取路由并导航到url。
import { Router } from '@angular.router';
...
constructor(private router: Router...) {
...
}
public callRedirection(apiEnd:, body: any): Observable<any> {
return this.http.post(endPoint, body)
.map((response) => {
//how to handle redirect here
this.router.navigate(response.url)
})
.catch(error => { console.log(error) });
}
注意:我不确定100%如何从响应中获取URL,但是我确定您可以在调试器中解决它:-)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.