C# 模拟from表单提交webservice

public static string test( string user_id, string eventId, string page, string pageSize, string message)//接口需要的参数自定义
{
string postUrl = "http:";//接口连接
string ret = string.Empty;//返回字符串
try
{
NameValueCollection na = new NameValueCollection();//添加参数
na.Add("user_id", user_id);
na.Add("eventId", eventId);
na.Add("pageOffset", page);
na.Add("pageSize", pageSize);

byte[] byteArray = System.Text.Encoding.UTF8.GetBytes(na.ToString());//编码格式
//HttpWebRequest webReq = (HttpWebRequest)WebRequest.Create(new Uri(postUrl));
System.Net.WebClient WebClientObj = new System.Net.WebClient();
byte[] bytes = WebClientObj.UploadValues(postUrl, "POST", na);//提交方式POST
string st = System.Text.Encoding.UTF8.GetString(bytes);得到返回的json
ret = st;
}
catch (Exception ex)
{
}
return ret;
}

原文地址:https://www.cnblogs.com/li-lun/p/4698788.html