WebApi后台调用put方式接口

[HttpPost]
[Route("api/order/PublicData/Add/")]
public int Add(users model)
{
string serviceAddress = "http://192.168.0.251:8887/aaa/user/cms";
HttpWebRequest request = (HttpWebRequest)WebRequest.Create(serviceAddress);
int[] roleIds = new int[] { 1 };
request.Method = "PUT";
request.ContentType = "application/json;charset=UTF-8";
request.Headers.Add("Access-Token", model.token.ToString());
//string strContent = @"{ ""roleIds"": ""123456"",""rememberMe"": ""false"",""userName"": ""jielio""}";
string strContent = @"{ ‘roleIds‘: " + "[1]" + ", ‘loginName‘: ‘" + model.loginName + "‘, ‘password‘: ‘" + model.password + "‘, ‘userName‘: ‘" + model.userName + "‘, ‘phonenumber‘: ‘" + model.phonenumber + "‘, ‘status‘: ‘" + model.status + "‘}";

using (StreamWriter dataStream = new StreamWriter(request.GetRequestStream()))
{
dataStream.Write(strContent);
dataStream.Close();
}
HttpWebResponse response = (HttpWebResponse)request.GetResponse();
string encoding = response.ContentEncoding;
if (encoding == null || encoding.Length < 1)
{
encoding = "UTF-8"; //默认编码
}
StreamReader reader = new StreamReader(response.GetResponseStream(), Encoding.GetEncoding(encoding));
string retString = reader.ReadToEnd();
//JObject jo = JObject.Parse(retString);
//解析josn
user jo1 = JsonConvert.DeserializeObject<user>(retString);
//return jo1;
return jo1.data;

}

WebApi后台调用put方式接口

上一篇:WinForm笔记1:TextBox编辑时和DataGridView 单元格编辑时 的事件及其顺序


下一篇:C#中二进制的写法