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

JS跨域代碼片段

 更新時(shí)間:2012年08月30日 12:04:49   作者:  
js跨域我用的比較多的就是jsonp和程序代理。但是jsonp只能用get,而且是js異步調(diào)用,有時(shí)候不能滿足項(xiàng)目要求
下面的代碼塊是js調(diào)用一般處理程序的代理來(lái)實(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)造請(qǐng)求
/// <summary>
/// 構(gòu)造請(qǐng)求
/// </summary>
/// <param name="requestUrl">請(qǐng)求地址</param>
/// <param name="requestParam">請(qǐng)求參數(shù)</param>
/// <param name="requestMethod">請(qǐng)求方式</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)文章

最新評(píng)論

汉寿县| 江口县| 大理市| 西峡县| 错那县| 清镇市| 忻城县| 子长县| 平乐县| 长岛县| 鸡东县| 富蕴县| 临湘市| 建阳市| 灌云县| 吉林省| 徐水县| 调兵山市| 顺昌县| 呼伦贝尔市| 沧州市| 临洮县| 阿坝| 武功县| 政和县| 青铜峡市| 西林县| 射阳县| 资兴市| 和田市| 辽阳县| 长顺县| 新营市| 肥西县| 孟津县| 蓝田县| 锡林郭勒盟| 合江县| 清涧县| 新源县| 嘉善县|