a标签在同源html中跳转,【基础】Html跨域跳转问题整理

$(function(){

$('#send').click(function(){

$.ajax({

type: "GET",

url: "http://localhost:PageB/",

data: {username:$("#username").val(), content:$("#content").val()}, dataType: "json", success: function(data){ $('#resText').empty(); //清空resText里面的所有内容 var html = ''; $.each(data, function(commentIndex, comment){ html += '

' + comment['username'] + ':
'; }); $('#resText').html(html); } }); }); });

2.通过Request模拟Post提交

类似以下这种后台模拟Request,答案是否定的

public string HttpPost(string Url, string postDataStr, HttpForType hft) {

SetAllowUnsafeHeaderParsing20(true);

HttpWebRequest request = (HttpWebRequest)WebRequest.Create(Url);

request.Method = "POST";

request.ContentType = "application/x-www-form-urlencoded";

request.CookieContainer = cookie; //cookie信息由CookieContainer自行维护

var sss11 = GetAllCookies(cookie);

request.UserAgent = "Mozilla/5.0 (compatible; MSIE 9.0; Windows NT 6.1; Win64; x64; Trident/5.0)";

Stream myRequestStream = request.GetRequestStream();

StreamWriter myStreamWriter = new StreamWriter(myRequestStream, Encoding.GetEncoding("gb2312"));

myStreamWriter.Write(postDataStr);

myStreamWriter.Close();

HttpWebResponse response = null;

try {

SetCertificatePolicy();

response = (HttpWebResponse)request.GetResponse();

} catch (System.Exception ex) {

return ex.Message.ToString();

}

//获取重定向地址

//string url1 = response.Headers["Location"];

if (response != null) {

var sss22 = GetAllCookies(cookie);

Stream myResponseStream = response.GetResponseStream();

StreamReader myStreamReader = new StreamReader(myResponseStream, Encoding.GetEncoding("utf-8"));

string retString = myStreamReader.ReadToEnd();

myStreamReader.Close();

myResponseStream.Close();

string retString = response.GetResponseHeader("Location");

return retString;

} else {

return "error"; //post请求返回为空

}

}

3.拼凑form表单形式Post提交

类似以下这种ajax,答案是肯定的,可以直接从 A页面 跳转到C页面(调试发现:B页面跳转C页面是在B页面后台处理的,处理完返回302跳转码和新地址到浏览器,302的新地址,header的location属性值就是C页面地址)

8ba1998913c9eb05399a1bd5ab6cace6.png

或者在A页面插入类似以下表单形式,答案也是可以跳转到C页面:

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值