在postman中的调用方式是这样的:
在C#中的写法:
public string PostFormData()
{
var url =$"http://127.0.0.1:8080/services/api/sendMessage";
var postContent = new MultipartFormDataContent();
postContent.Headers.Add("ContentType", $"multipart/form-data");
//value-key 键值对
postContent.Add(new StringContent("switch"), "function");
postContent.Add(new StringContent("eb6860e131ea453d9b01d33026788117"), "id");
//这是Json-key的键值对,param是一个类的对象
//postContent.Add(new StringContent(param.ToJsonStr()), "content");
//form表单格式传参
string result = "";
try
{
HttpClient client = new HttpClient();
HttpResponseMessage response = client.PostAsync(url, postContent).Result;
result = response.Content.ReadAsStringAsync().Result;
}
catch (Exception ex)
{
result = ex.Message;
}
return result;
}
有什么错误欢迎指正,共同进步!