[英]Can I post json object from model class to angular .ts file
I am retrieving XML result from thrid-party API to ASP.net web API.我正在从第三方 API 检索 XML 结果到 ASP.net Web API。 Now I want to send this retrieved XML( converted in JSON) to angular typescript file.
现在我想将此检索到的 XML(以 JSON 格式转换)发送到 angular typescript 文件。 How can I achieve it?
我怎样才能实现它?
My approach 1. send JSON from model class to controller and then from the controller to angular service or component's .ts file.我的方法 1. 将 JSON 从模型类发送到控制器,然后从控制器发送到角度服务或组件的 .ts 文件。 2.post from model class to component's .ts file.
2.从模型类发布到组件的 .ts 文件。
var objJson = new JavaScriptSerializer().Serialize(responseB);
var response = await client.PostAsync("http://localhost:4200/add", new StringContent(objJson, Encoding.UTF8, "application/json"));
var responseString = await response.Content.ReadAsStringAsync();
You can't send something "from a WebAPI to a TypeScript file".您不能“从 WebAPI 发送到 TypeScript 文件”。
It sounds like you want to send it from the server to a client app in a web browser?听起来您想将它从服务器发送到 Web 浏览器中的客户端应用程序? If this is the case, then you need the client app to ask for it, or to push it to the client.
如果是这种情况,那么您需要客户端应用程序来请求它,或者将它推送给客户端。
If the client initiated the request that had you fetch this resource, then you could send it in the response to the client.如果客户端发起了让您获取此资源的请求,那么您可以在响应中将其发送给客户端。
If the client app has some bi-directional connection to your server like socket.io or SignalR , you can send it over that.如果客户端应用程序与您的服务器有某种双向连接,例如socket.io或SignalR ,您可以通过它发送它。
Or, depending on the frequency, probability of this happening, you might have the client poll for it.或者,根据发生这种情况的频率和概率,您可以让客户端对其进行轮询。
But it all depends on the state machine of the entire process you are implementing.但这一切都取决于您正在实施的整个过程的状态机。 Does the client app initiate any of this, or this an event that the client does not initiate, but needs to be informed of?
客户端应用程序是否启动了其中的任何一个,或者这是一个客户端未启动但需要通知的事件? If this is the case, you either need to poll or to set up a connection from the client to the server.
如果是这种情况,您需要轮询或建立从客户端到服务器的连接。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.