最新国产好看的视频,伊人天堂AV在线,国产Aaaaaa视频,蜜臀视频在线观看一区,人妻av色图,密臀久久久精品影片,青青视频免费观看毛片,久草在线观看视,国产三级精品色情在线

JS跨域代碼片段

 更新時(shí)間:2012年08月30日 12:04:49   作者:  
js跨域我用的比較多的就是jsonp和程序代理。但是jsonp只能用get,而且是js異步調(diào)用,有時(shí)候不能滿足項(xiàng)目要求
下面的代碼塊是js調(diào)用一般處理程序的代理來實(shí)現(xiàn)js跨域的。如果js需要多次跨域,推薦下面的方法。

復(fù)制代碼 代碼如下:

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

相關(guān)文章

最新評論

芒康县| 霍州市| 章丘市| 涿州市| 邵阳县| 望谟县| 嘉峪关市| 靖安县| 资阳市| 且末县| 页游| 北京市| 嘉定区| 通化县| 五寨县| 水富县| 富源县| 梓潼县| 麻江县| 衡阳市| 沈丘县| 广宁县| 济南市| 馆陶县| 定日县| 荥经县| 青田县| 阳谷县| 湖南省| 望都县| 西宁市| 萍乡市| 东乡| 刚察县| 内黄县| 翁牛特旗| 太保市| 仙桃市| 吐鲁番市| 凤翔县| 抚顺县|