//get 请求
string url = string.Format("http://localhost:28450/api/values?str1=a&str2=b");
WebClient wc = new WebClient();
Encoding enc = Encoding.GetEncoding("UTF-8");
Byte[] pageData = wc.DownloadData(url);DownloadString(url);
string re = enc.GetString(pageData);
//post 请求
string postData = "value=a";
byte[] bytes = Encoding.UTF8.GetBytes(postData);
WebClient client = new WebClient();
client.Headers.Add("Content-Type", "application/x-www-form-urlencoded");
client.Headers.Add("ContentLength", postData.Length.ToString());
Encoding enc = Encoding.GetEncoding("UTF-8");
byte[] responseData = client.UploadData("http://localhost:28450/api/values", "POST", bytes);
string re = enc.GetString(responseData);
//调用接口Demo
string url = "http://localhost:62691/SessionState/TransmitSession";//获取会话同步接口 string sendAccount = "fff2221111"; string acceptedAccount = "qckf_wx"; string msgType = "text"; string content = "测试下22"; string nickname = "山本松井"; //调用接口进行同步 string timeStamp = GetTimeStamp();//获取时间戳 string sign = DESEncrypt.Encrypt(timeStamp, "dxqmp52c0esxymru"); string postData = "sendAccount=" + sendAccount + "&acceptedAccount=" + acceptedAccount + "&msgType=" + msgType + "&content=" + content + "×tamp=" + timeStamp + "&sign=" + sign + "&nickname=" + nickname + ""; byte[] bytes = Encoding.UTF8.GetBytes(postData); WebClient client = new WebClient(); client.Headers.Add("Content-Type", "application/x-www-form-urlencoded"); client.Headers.Add("ContentLength", postData.Length.ToString()); Encoding enc = Encoding.GetEncoding("UTF-8"); byte[] responseData = client.UploadData(url, "POST", bytes); string re = enc.GetString(responseData);