首頁 >web前端 >js教程 >JS跨域程式碼片段_javascript技巧

JS跨域程式碼片段_javascript技巧

WBOY
WBOY原創
2016-05-16 17:50:341018瀏覽

下面的程式碼區塊是js呼叫一般處理程序的代理來實作js跨域的。如果js需要多次跨域,推薦下面的方法。

複製程式碼 程式碼如下:

public string GetInfoInfoInfo >{
string post = "a=XX&b=XX";
return CreateHttpRequest("https://www.XXXX.com", post, "POST");
}


#region 建構請求
///
/// 建構請求
///

/// 請求位址
/// 請求參數
/// 請求方式
// /
public string CreateHttpRequest(string requestUrl, string requestParam, string requestMethod)
{
try
{
System.Net.Net.Request. HttpWebRequest.Create(requestUrl) as System.Net.HttpWebRequest;
request.Method = requestMethod;
string post = requestParam;

byte[] bytes = System.Text.Encodinget.F8. (post);
request.ContentType = "application/x-www-form-urlencoded";
request.ContentLength = "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;
Streamystem.L. .IO.StreamReader(response.GetResponseStream(), System.Text.Encoding.UTF8);
return sr.ReadToEnd();
}
catch (Exception)
{
}
catch (Exception)
{
}
catch (Exception)
{
} catch (Exception) { } catch (Exception) { } catch (Exception) { } catch (Exception) { } catch (Exception) { ) "; } } #endregion
陳述:
本文內容由網友自願投稿,版權歸原作者所有。本站不承擔相應的法律責任。如發現涉嫌抄襲或侵權的內容,請聯絡admin@php.cn