【问题标题】:calling web service using POST to retrieve data using ASP.NET使用 POST 调用 Web 服务以使用 ASP.NET 检索数据
【发布时间】:2018-06-06 06:53:32
【问题描述】:

我有一个任务要使用 c# 和 ASP 调用我们的服务,我在这个任务中只有一个 LINK,它不是 .asmx 或 wsdl,它是一个普通的链接,如 https://www.normallink.com

我使用 Postman 扩展尝试了这个链接,它使用 POST 方法带来了一个 json 数据,所以我如何使用 ASP 检索这些数据

这是来自 Postman 的 json 数据示例

 "data": [
    {
        "id": "516",
        "name": "xyz"
    }, 

【问题讨论】:

  • 你可以尝试用谷歌搜索“c# call web service using POST”并查看在线提供的数千个示例

标签: c# asp.net json ajax web-services


【解决方案1】:

我想这就是你要找的东西:

String jsonData = ...; 

WebRequest request = WebRequest.Create("http://www.mywebservice.com/");
request.ContentType = "application/json";
request.Method = "POST";

using (Stream postStream = request.GetRequestStream())
{
    using (StreamWriter postWriter = new StreamWriter(postStream))
        postWriter.Write(jsonData);
}

WebResponse response = request.GetResponse();
String responseContent;

using (Stream stream = response.GetResponseStream())
{
   using (StreamReader reader = new StreamReader(stream, Encoding.UTF8))
       responseContent = reader.ReadToEnd();
}

【讨论】:

  • 感谢您的回复....但它不起作用请您给我更多解释吗?
  • 好吧,“它不工作有点太笼统了”如果你想要一些提示,你必须告诉我更多关于这个......
猜你喜欢
  • 1970-01-01
  • 2017-01-09
  • 1970-01-01
  • 2021-05-27
  • 2012-05-20
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2011-09-30
相关资源
最近更新 更多