900字范文,内容丰富有趣,生活中的好帮手!
900字范文 > c# http模拟post请求 解决参数很大的情况

c# http模拟post请求 解决参数很大的情况

时间:2019-01-20 17:18:29

相关推荐

c# http模拟post请求 解决参数很大的情况

public static string HttpPost(string url, Dictionary<string, string> parms){try{string result = string.Empty;//设置Http的正文FormUrlEncodedContent httpContent = new FormUrlEncodedContent(parms);using (HttpClient httpClient = new HttpClient()){//异步PostHttpResponseMessage response = httpClient.PostAsync(url, httpContent).Result;//输出Http响应状态码//确保Http响应成功if (response.IsSuccessStatusCode){//异步读取jsonresult = response.Content.ReadAsStringAsync().Result;}}return result;}catch (HttpRequestException ex){LogManager.WriteError("HttpPost", "token:" + LoginUserInfo.CurrentUser.token + "请求url:" + url);var msg = "{ code:404 ,data: '',msg: '" + ex.Message + "'}";return msg;}}

//调用实列string token = this.token;string url = "http://localhost:80/api";Dictionary<string, string> dic = new Dictionary<string, string>{{ "token", "0f1u2c3k" },{ "lx", "0" },{ "data", jsonStr }};var handle = APIHelper.HttpPost("http://localhost:8080/api", dic);

本内容不代表本网观点和政治立场,如有侵犯你的权益请联系我们处理。
网友评论
网友评论仅供其表达个人看法,并不表明网站立场。