码迷,mamicode.com
首页 > Windows程序 > 详细

WebApi后台调用put方式接口

时间:2019-05-27 16:33:30      阅读:450      评论:0      收藏:0      [点我收藏+]

标签:reader   解析   token   remember   ons   model   des   using   add   

[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方式接口

标签:reader   解析   token   remember   ons   model   des   using   add   

原文地址:https://www.cnblogs.com/tfeblog/p/10931281.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!