public static string HttpGet(string Url, string postDataStr)
{
HttpWebRequest request = (HttpWebRequest)WebRequest.Create(Url + (postDataStr == "" ? "" : "?") + postDataStr);
request.Method = "GET";
request.ContentType = "text/html;charset=UTF-8"; HttpWebResponse response;
try
{
response = (HttpWebResponse)request.GetResponse();
}
catch (WebException exc)
{
response = (HttpWebResponse)exc.Response;
}
Stream myResponseStream = response.GetResponseStream();
StreamReader myStreamReader = new StreamReader(myResponseStream, Encoding.GetEncoding("utf-8"));
string retString = myStreamReader.ReadToEnd();
myStreamReader.Close();
myResponseStream.Close(); return retString;
}

  

  

        /// <summary>
/// 返回JSon数据
/// </summary>
/// <param name="parameter">需要传递的数据,没有则传递null</param>
/// <param name="Url">要提交的URL</param>
/// <returns>返回的数据</returns>
public static string GetResponseData(string parameter, string Url, RequestMethod method)
{
bool isWrite=false; HttpWebRequest request = (HttpWebRequest)WebRequest.Create(Url); request.Method = method.ToString(); if (!String.IsNullOrEmpty(parameter))
{
byte[] bytes = Encoding.UTF8.GetBytes(parameter);
request.ContentLength = bytes.Length;
request.ContentType = "text/plain";
Stream reqstream = request.GetRequestStream();
reqstream.Write(bytes, 0, bytes.Length);
} request.ServicePoint.Expect100Continue = false;
//声明一个HttpWebRequest请求
request.Timeout = 10 * 1000;
//设置连接超时时间
request.Headers.Set("Pragma", "no-cache");
HttpWebResponse response = null;
try
{
response = (HttpWebResponse)request.GetResponse();
}
catch (WebException exc)
{
response = (HttpWebResponse)exc.Response;
isWrite = true;
} Stream streamReceive = response.GetResponseStream();
Encoding encoding = Encoding.UTF8; StreamReader streamReader = new StreamReader(streamReceive, encoding);
string strResult = streamReader.ReadToEnd();
streamReceive.Dispose();
streamReader.Dispose(); if (isWrite)
{
WriteLog.Log("HttpWebRequest异常:" + strResult, "HttpWebRequest异常.txt");
WriteLog.Log("JSONData:" + parameter, "HttpWebRequest异常.txt");
WriteLog.Log("Url:" + Url, "HttpWebRequest异常.txt");
} return strResult;
}

  

HttpGet HttpPost的更多相关文章

  1. ajax参数传递之[HttpGet]/[HttpPost]/[HttpPut]/[HttpDelete]请求

    $.ajax({ type: "get", url: "http://localhost:27221/api/Charging/GetByModel", con ...

  2. httpClient Post例子,Http 四种请求访问代码 HttpGet HttpPost HttpPut HttpDelete

    httpclient post方法 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 //----1. HttpPost request = new HttpPost(ur ...

  3. Http 四种请求访问代码 HttpGet HttpPost HttpPut HttpDelete .

    String url = "http://www.baidu.com"; //将要访问的url字符串放入HttpPost中 HttpPost httpPost= new HttpP ...

  4. ActionResult 之HttpGet HttpPost

    GET一般用于获取和查询数据. 当浏览器发送HTTP GET 请求的时候,会找到使用HttpGet限定的对应Action. POST 一般用于更新数据. 当Action上面没有限定的时候,浏览器发送任 ...

  5. Web Service进阶(三)HTTP-GET, HTTP-POST and SOAP的比较

    XML Web Service支持三种协议来与用户交流数据.这三种协议分别是: 1.SOAP:Simple Object Access Protocol 2.HTTP-GET 3.HTTP-POST ...

  6. HttpGet/HttpPost请求方法

    /// <summary> /// HttpGet请求 /// </summary> /// <param name="url">HttpGet ...

  7. Android数据与服务器交互的GET,POST,HTTPGET,HTTPPOST的使用

    Android有这几种方式,可以提交数据到服务器,他们是怎么使用的呢,这里我们来探讨一下. 这里的例子用的都是提交客户端的用户名及密码,同时本节用到的StreamTools.readInputStre ...

  8. android 网络连接 HttpGet HttpPost方法

    1.本文主要介绍利用HttpGet和HtppPost方法来获取网络json数据. 代码如下: public HttpData(String Url,HttpGetDataListener listen ...

  9. 译-HTTP-GET HTTP-POST SOAP protocol for ASP.NET services的异同

    参考 http://stackoverflow.com/questions/4646146/http-soap-get-post https://support.microsoft.com/en-us ...

随机推荐

  1. winApi

    using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.R ...

  2. Fedora23Server配置

    系统准备 启动网卡: sudo service network start 更新系统: sudo dnf update 远程管理: https://IP:9090/ Dnf使用: http://www ...

  3. java 27 - 9 反射之 动态代理的概述和实现

    代理:本来应该自己做的事情,却请了别人来做,被请的人就是代理对象. 举例:春季回家买票让人代买 动态代理: 在程序运行过程中产生的这个对象 而程序运行过程中产生对象其实就是我们刚才反射讲解的内容,所以 ...

  4. SDWebImage ReadMe.md文档简单说明

    SDWebImage ReadMe.md 文档 附:SDWebImage框架github下载地址:https://github.com/rs/SDWebImage 注1:该文章简单翻译了SDWebIm ...

  5. 在执行Action之间检验是否登录

    在执行Action之间检验是否登录,也可以在执行Action前先执行某一个操作 public class BaseController : Controller { protected string ...

  6. Codeforces Round #334 (Div. 2) B. More Cowbell 二分

    B. More Cowbell Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/contest/604/probl ...

  7. android学习日记03--常用控件progressbar/seekbar

    常用控件 5.progressbar 进度条,比较常用的组件,在某些操作的进度中的可视指示器,为用户呈现操作的进度,还它有一个次要的进度条,用来显示中间进度,如在流媒体播放的缓冲区的进度.一个进度条也 ...

  8. Example: Develop Web application on Baidu App Engine using CherryPy

    In the past few months, I have developed two simple applications on Baidu App Engine. Compared to Go ...

  9. 使用资源监控工具 glances

    http://www.ibm.com/developerworks/cn/linux/1304_caoyq_glances/ glances 可以为 Unix 和 Linux 性能专家提供监视和分析性 ...

  10. Linux最小系统移植之早期打印CONFIG_DEBUG_LL

    一.几个关键宏定义 CONFIG_DEBUG_LL. CONFIG_DEBUG_LL_INCLUDE 容我慢慢道来, 首先要使能早期打印, menuconfig必须选中CONFIG_DEBUG_LL, ...