您的位置:首页 > 编程语言 > C#

C# 模拟from表单提交webservice

2015-08-03 11:05 344 查看
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;
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: