Compare commits
2 Commits
ea7af395f3
...
ded64087e3
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
ded64087e3 | ||
|
|
7063675379 |
55
Ewide.NbzsZheliban/Tools/HttpHelper.cs
Normal file
55
Ewide.NbzsZheliban/Tools/HttpHelper.cs
Normal file
@@ -0,0 +1,55 @@
|
|||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.IO;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Net;
|
||||||
|
using System.Text;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
|
||||||
|
namespace Ewide.NbzsZheliban.Tools
|
||||||
|
{
|
||||||
|
public class HttpHelper
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// 请求网页地址
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="url">网页地址</param>
|
||||||
|
/// <param name="param">参数</param>
|
||||||
|
/// <returns></returns>
|
||||||
|
public static string CallUrl(string url, string param)
|
||||||
|
{
|
||||||
|
//创建一个HTTP请求
|
||||||
|
HttpWebRequest request = (HttpWebRequest)WebRequest.Create(url);
|
||||||
|
//Post请求方式
|
||||||
|
request.Method = "POST";
|
||||||
|
//内容类型
|
||||||
|
//request.ContentType = "application/x-www-form-urlencoded";
|
||||||
|
request.ContentType = "application/json;charset=utf-8";
|
||||||
|
//byte[] bs = Encoding.ASCII.GetBytes(param); //参数转化为ascii码
|
||||||
|
byte[] bs = Encoding.UTF8.GetBytes(param);
|
||||||
|
request.ContentLength = bs.Length;
|
||||||
|
using (Stream reqStream = request.GetRequestStream())
|
||||||
|
{
|
||||||
|
reqStream.Write(bs, 0, bs.Length);
|
||||||
|
}
|
||||||
|
|
||||||
|
String strValue = "";//strValue为http响应所返回的字符流
|
||||||
|
HttpWebResponse response;
|
||||||
|
try
|
||||||
|
{
|
||||||
|
//获得响应流
|
||||||
|
response = (HttpWebResponse)request.GetResponse();
|
||||||
|
}
|
||||||
|
catch (WebException ex)
|
||||||
|
{
|
||||||
|
response = ex.Response as HttpWebResponse;
|
||||||
|
}
|
||||||
|
|
||||||
|
Stream s = response.GetResponseStream();
|
||||||
|
StreamReader sr = new StreamReader(s);
|
||||||
|
|
||||||
|
strValue = sr.ReadToEnd();
|
||||||
|
return strValue;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
@@ -1 +1 @@
|
|||||||
919fb30d2a97726031adcb9ca38853405bac0fd6
|
4bde41c8041738fd99537bb8a528c2972537dead
|
||||||
|
|||||||
Binary file not shown.
Binary file not shown.
Binary file not shown.
Reference in New Issue
Block a user