HttpClient post
usingSystem;usingSystem.Collections.Generic;usingSystem.Linq;usingSystem.Net.Http;usingSystem.Text;usingSystem.Threading.Tasks;usingXinleda.Common;usingXinleda.Model;namespaceConsoleApplication1{classProgram{staticvoidMain(string[]args){HttpClientclient=newHttpClient();FormUrlEncodedContentcontent=newFormUrlEncodedContent(newList<KeyValuePair<string,string>>(){newKeyValuePair<string,string>("batdata[0].id","213"),newKeyValuePair<string,string>("token","qwe")});varresult=client.PostAsync("http://localhost:55787/api/XldSalary/Update",content).Result.Content.ReadAsStringAsync().Result;Console.WriteLine(result);Console.ReadKey();}}}
UploadPaydataModelmodel=newXinleda.Model.UploadPaydataModel();model.entrname="上海有限公司";model.batdata=newList<batdata>(){newbatdata(){bank="名还是呢过"}};varcontent=SerializerHelper.JsonSerialize(model);WebRequestrequest=HttpWebRequest.Create("http://localhost:55787/api/XldSalary/Update");request.ContentType="application/json";request.Method="post";using(StreamWritersw=newStreamWriter(request.GetRequestStream())){sw.Write(content);sw.Close();}WebResponser=request.GetResponse();stringresult="";using(StreamReadersr=newStreamReader(r.GetResponseStream())){result=sr.ReadToEnd();sr.Close();}Console.WriteLine(result);Console.ReadKey();
声明:本站所有文章资源内容,如无特殊说明或标注,均为采集网络资源。如若本站内容侵犯了原著者的合法权益,可联系本站删除。