/// <summary>
/// Get方法
/// </summary>
/// <param name="serverUrl">url地址</param>
/// <param name="postData">数据 格式为"aa=xx&bb=xxx"</param>
/// <returns>请求结果</returns>
public static string HttpGetConnectToServer(string serverUrl, string postData)
{
//创建请求
var request = (HttpWebRequest)HttpWebRequest.Create(serverUrl + "?" + postData);
request.Method = "GET";
//设置上传服务的数据格式
request.ContentType = "application/x-www-form-urlencoded";
//请求的身份验证信息为默认
request.Credentials = CredentialCache.DefaultCredentials;
//请求超时时间
request.Timeout = ;
//读取返回消息
string res = "";
try
{
var response = (HttpWebResponse)request.GetResponse();
var reader = new StreamReader(response.GetResponseStream(), Encoding.UTF8);
res = reader.ReadToEnd();
reader.Close();
}
catch (Exception ex)
{ }
return res;
} /// <summary>
/// post方法
/// </summary>
/// <param name="postUrl">url地址</param>
/// <param name="paramData">提交的ParamData对象</param>
/// <returns></returns>
public static string PostWebRequest<T>(string postUrl, T paramData)
{
string ret = string.Empty;
try
{
string str_Tem = JsonSerializer(paramData);//将对象转成json串
byte[] byteArray = System.Text.Encoding.UTF8.GetBytes(str_Tem);
HttpWebRequest webReq = (HttpWebRequest)WebRequest.Create(new Uri(postUrl));
webReq.Method = "POST";
webReq.ContentType = " application/json; charset=utf-8";
webReq.ContentLength = byteArray.Length;
Stream newStream = webReq.GetRequestStream();
newStream.Write(byteArray, , byteArray.Length);//写入参数
newStream.Close();
HttpWebResponse response = (HttpWebResponse)webReq.GetResponse();
StreamReader sr = new StreamReader(response.GetResponseStream(), Encoding.UTF8);
ret = sr.ReadToEnd();
sr.Close();
response.Close();
newStream.Close();
}
catch (Exception ex)
{ }
return ret;
}

随机推荐

  1. BZOJ 3563 DZY Loves Chinese

    Description 神校XJ之学霸兮,Dzy皇考曰JC. 摄提贞于孟陬兮,惟庚寅Dzy以降. 纷Dzy既有此内美兮,又重之以修能. 遂降临于OI界,欲以神力而凌♂辱众生. 今Dzy有一魞歄图,其上 ...

  2. [UOJ 74] 【UR #6】破解密码

    题目链接:UOJ - 74 题目分析 题目中,将字符串 S 的第一个字符移到末尾,其他字符向前移动一个位置,f(S) 就从 Hi 变成了 Hi+1. 我们分析一下这个过程:假设第一个字符为 c, (H ...

  3. Reverse Linked List 递归非递归实现

    单链表反转--递归非递归实现 Java接口: ListNode reverseList(ListNode head) 非递归的实现 有2种,参考 头结点插入法 就地反转 递归的实现 1) Divide ...

  4. Coach(并查集)

    Description A programming coach has n students to teach. We know that n is divisible by 3. Let's ass ...

  5. 别再说“我已经努力了”,你的“努力”一文不值!

    有次,让一个研究生男收集一份资料,快下班了问结果,竟然毛也没有.见我要怒,他慷慨激昂地说:"我已经很努力找了,但真的查不到." 作为主管,"我已经努力"这话我不 ...

  6. HDU-4089 Activation

    http://acm.hdu.edu.cn/showproblem.php?pid=4089 Activation Time Limit: 20000/10000 MS (Java/Others)   ...

  7. [SSD大法好]神舟K480-I5-D3鸟枪换炮M6S

    Hello,SSD 期盼已久,终于入手了M6S的256G固态硬盘,白天就不安生一直百度.谷歌.必应,势必要把所有相关消息查个清楚这神舟K480I5D3怎生拆呢. 最后心里隐约有了安装的法门. 但到得开 ...

  8. Learn Objectvie-C on the Mac 2nd Edition 笔记

    Chapter 1Apple’s Cocoa (for OS X) 和 Cocoa Touch (for iOS) toolkits 都是用 Objective-C写的. Chapter 2 (1)  ...

  9. Tree2cycle

    Problem Description A tree with N nodes and N-1 edges is given. To connect or disconnect one edge, w ...

  10. Div 3 - SGU 105(找规律)

    分析:很容易知道序列1,2,3, 4,5, 6......与3的关系就是1,2, 0,1, 2,0,......如果是在一个数后面添加一个数就变成了这种序列1, 0, 0, 1, 0, 0, 1, 0 ...