api接口为:http://localhost:63300/api/Pms/TaskAdd 现在需要模拟api接口发送如下信息:{ "WareHouseCode": "原材料", "LocationCode": "", "MaterialId": "满托盘", "TargetWareHouseCode": "", "TargetLocationCode": "工位1" }
时间: 2023-08-22 09:04:04 浏览: 170
PMS软件:Schneider Electric PMS二次开发-API接口使用与开发
好的,您可以使用以下代码来模拟发送POST请求:
```csharp
using System;
using System.Net.Http;
using System.Text;
using System.Threading.Tasks;
namespace ConsoleApp
{
class Program
{
static async Task Main(string[] args)
{
var requestBody = "{\"WareHouseCode\":\"原材料\",\"LocationCode\":\"\",\"MaterialId\":\"满托盘\",\"TargetWareHouseCode\":\"\",\"TargetLocationCode\":\"工位1\"}";
var requestContent = new StringContent(requestBody, Encoding.UTF8, "application/json");
var httpClient = new HttpClient();
var response = await httpClient.PostAsync("http://localhost:63300/api/Pms/TaskAdd", requestContent);
var responseContent = await response.Content.ReadAsStringAsync();
Console.WriteLine(responseContent);
}
}
}
```
需要注意的是,这里的requestBody是您要发送的JSON字符串,需要根据实际情况进行修改。同时,如果您的接口需要进行身份验证,还需要在请求头中添加相应的身份验证信息。
阅读全文