国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 語言 > JavaScript > 正文

JS跨域代碼片段

2024-05-06 14:21:20
字體:
供稿:網(wǎng)友
下面的代碼塊是js調(diào)用一般處理程序的代理來實(shí)現(xiàn)js跨域的。如果js需要多次跨域,推薦下面的方法。

代碼如下:
public string GetInfo(HttpContext context)
{
string post = "a=XX&b=XX";
return CreateHttpRequest("https://www.XXXX.com", post, "POST");
}


#region 構(gòu)造請求
/// <summary>
/// 構(gòu)造請求
/// </summary>
/// <param name="requestUrl">請求地址</param>
/// <param name="requestParam">請求參數(shù)</param>
/// <param name="requestMethod">請求方式</param>
/// <returns></returns>
public string CreateHttpRequest(string requestUrl, string requestParam, string requestMethod)
{
try
{
System.Net.HttpWebRequest request = System.Net.HttpWebRequest.Create(requestUrl) as System.Net.HttpWebRequest;
request.Method = requestMethod;
string post = requestParam;

byte[] bytes = System.Text.Encoding.UTF8.GetBytes(post);
request.ContentType = "application/x-www-form-urlencoded";
request.ContentLength = bytes.Length;
System.IO.Stream stream = request.GetRequestStream();
stream.Write(bytes, 0, bytes.Length);
System.Net.HttpWebResponse response = request.GetResponse() as System.Net.HttpWebResponse;
System.IO.StreamReader sr = new System.IO.StreamReader(response.GetResponseStream(), System.Text.Encoding.UTF8);
return sr.ReadToEnd();
}
catch (Exception)
{
return "";
}

}
#endregion
發(fā)表評論 共有條評論
用戶名: 密碼:
驗(yàn)證碼: 匿名發(fā)表

圖片精選

主站蜘蛛池模板: 东乌珠穆沁旗| 云林县| 福安市| 忻城县| 洱源县| 米林县| 土默特左旗| 集贤县| 石楼县| 湘乡市| 视频| 离岛区| 清原| 甘洛县| 蒙自县| 喜德县| 南通市| 南皮县| 九龙县| 黄冈市| 唐山市| 柞水县| 泰州市| 桐梓县| 上饶市| 弥勒县| 上林县| 当雄县| 芒康县| 望谟县| 永仁县| 嘉兴市| 祁连县| 永昌县| 磐安县| 栖霞市| 读书| 新营市| 泽库县| 广西| 都江堰市|