try
{
///URL接口地址
HttpWebRequest request = (HttpWebRequest)WebRequest.Create(URL);
request.Proxy = null;
request.KeepAlive = false;
request.Method = "GET";
request.ContentType = "application/json; charset=UTF-8";
request.AutomaticDecompression = DecompressionMethods.GZip;
string Data = "{\"CorpId\":\"300014\"}";///Json参数
var type = request.GetType();
var currentMethod = type.GetProperty("CurrentMethod", BindingFlags.NonPublic | BindingFlags.Instance).GetValue(request);
var methodType = currentMethod.GetType();
methodType.GetField("ContentBodyNotAllowed", BindingFlags.NonPublic | BindingFlags.Instance).SetValue(currentMethod, false);
using (var streamWriter = new StreamWriter(request.GetRequestStream()))
{
streamWriter.Write(Data);
}
HttpWebResponse response = (HttpWebResponse)request.GetResponse();
Stream myResponseStream = response.GetResponseStream();
StreamReader myStreamReader = new StreamReader(myResponseStream, Encoding.UTF8);
string retString = myStreamReader.ReadToEnd();
myStreamReader.Close();
myResponseStream.Close();
if (response != null)
{
response.Close();
}
if (request != null)
{
request.Abort();
}
return retString;
}
catch (Exception ex)
{
return ("ERROR:" + ex.Message + ":" + ex.InnerException.Message);
}
相关文章
- 12-22mock server 实现get方法的接口(二)
- 12-22接口测试中GET和POST两种基本HTTP请求方法的区别
- 12-22httprunner 3 带参数接口测试(get方法)
- 12-22接口get方法body赋值
- 12-22jquery中Get方法请求接口
- 12-22PHP其它常用函数;<<<面向对象(OPP)的三大特性:封装、继承、加态:>>> <----面试题 ;构造方法、析构方法,魔术方法、set、get方法;静态;抽象类;接口
- 12-22Postman接口测试之POST、GET请求方法
- 12-22【转】Postman接口测试之POST、GET请求方法
- 12-22创建包含CRUD操作的Web API接口2:实现Get方法
- 12-22RobotFramework下的http接口自动化Get Response Body关键字的使用