简体   繁体   English

从asp.net MVC操作方法将Json对象发布到外部API

[英]Posting Json object to an external API from asp.net mvc action method

I want to integrate with a 3rd party Rest API. 我想与第三方Rest API集成。 Now the API have the following definition for a Create operation:- 现在,API对创建操作具有以下定义:-

> URL :-  https://<IP address>:7272/restapi/json/v1/resources?AUTHTOKEN
> HTTP METHOD: POST
> 
> Sample Requests
> 
> curl -X POST -k -H "Content-Type: text/json" 
> 'https://IP:7272/restapi/json/v1/resources?AUTHTOKEN=***'
> -d  'INPUT_DATA={"operation":{"Details":{"RESOURCENAME":"Windows  Server","ACCOUNTNAME":"Administrator","RESOURCETYPE":"Windows","PASSWORD"
> :"Test123#@!","NOTES":"Testing 
> API","RESOURCEURL":"http://windowsserver/adminconsole","RESOURCECUSTOMFIEL
> D":[{"CUSTOMLABEL":"Secure Resource","CUSTOMVALUE":"YES"}]}}}'

so can anyone advice how I can post JSON to the API from my action method? 所以任何人都可以建议我如何从我的操作方法将JSON发布到API? I usually use WebClient.DownloadString to receive json from the API,, but not sure how I can send json object ? 我通常使用WebClient.DownloadString从API接收json,但不确定如何发送json对象?

On how to send a POST request, look here for example: HTTP request with post 有关如何发送POST请求的信息,请看此处: 带post的HTTP请求

For creating the JSON data, you could use a library like the excellent Json.NET http://www.newtonsoft.com/json or build the string on your own. 为了创建JSON数据,您可以使用类似Json.NET的http://www.newtonsoft.com/json这样的库,也可以自行构建字符串。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM