我想与第三方Rest API集成。现在,API对Create操作有以下定义: -
> 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"}]}}}'
所以有人可以建议我如何从我的action方法向API发布JSON?我通常使用WebClient.DownloadString从API接收json,但不知道如何发送json对象?
答案 0 :(得分:2)
关于如何发送POST请求,请查看此处:HTTP request with post
为了创建JSON数据,您可以使用像优秀的Json.NET http://www.newtonsoft.com/json这样的库,或者自己构建字符串。