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;
}
{
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;
}
相关文章推荐
- C#匿名类的使用
- C#高级编程六十四天----并行扩展
- C#获取进程的主窗口句柄的实现方法
- C# winform键盘钩子
- C#如何自动选择出系统中最合适的IP地址
- C#将字节数组加到List中
- C#读取数组中的指定长度
- C#中的 SET ,GET
- C# 冒泡排序
- C#在获取当前方法名、类名
- 扩展方法为我们带来了什么
- C# StopWatch 类
- C#中WebClient使用DownloadString中文乱码的解决办法
- c#的DateTime.Now函数详解
- c#读写excel
- c#群发短信
- C#脚本引擎 CS-Script 之(一)——初识
- C# Hadoop学习笔记(一)
- c#region
- C#常见问题总结