ASP.NET 通过HttpWebRequest 以GET形式传参请求数据,参数为键值对格式。
需要进行Token值验证。
注意!!authorization需要放入请求头部,详细代码如下所示。
authorization=bearer eyJhbGciOiJSUzI1NiIsInR5cCI6IkpXVCJ9.eyJ1aWQiOiI3MDE1MTQ0NzM0NSIsInBpZCI6IjAxOTY3MTg5Mzc2IiwiZW50IjoiMDE5NjcxODkzNzYiLCJ0eXBlIjoiV0VCIiwiZXhwIjoxNTYwNjA2MjIwLCJqdGkiOiJkNDlhZWFkMi1lM2FhLTQ5MGItYWZiMC1iNmVmNDNmMTY5Y2UiLCJyb2xlcyI6W119.Vdumf8OOcLnfu8i2KiP7qzN1nPmSXmcwnH74LKFsydImgcVIBMT9rV4zCz8UnJxQq55XIQr1IjiAe1cIYEtESw==
using System;
using System.IO;
using System.Net;
using System.Text;
public partial class GetData : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
string authorization = Request.Params["authorization"];//需要输入的参数值
HttpWebRequest request = (HttpWebRequest)WebRequest.Create("https://.....");//请求URL地址
request.Method = "GET";
request.ContentType = "text/html;charset=UTF-8";
if (authorization != null)
{
request.Headers.Add("Authorization", authorization);//有前端提供具体authorization的值
HttpWebResponse response = (HttpWebResponse)request.GetResponse();
Stream myResponseStream = response.GetResponseStream();
StreamReader myStreamReader = new StreamReader(myResponseStream, Encoding.UTF8);
string retString = myStreamReader.ReadToEnd();
Response.Write(retString);
myStreamReader.Close();
myResponseStream.Close();
response.Close();
}
}
}