【发布时间】:2014-11-08 10:45:53
【问题描述】:
我在这里阅读了有关跨域帖子的一些问题和答案,但我仍然无法使其正常工作。任务看起来很简单,但我从接收端得到的数据却始终为空。
在 Web 应用程序 1(发件人)中,我有这个 TestCrossDomainPost.html:
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title></title>
</head>
<body>
<form action="http://localhost:55400/TestCrossDomainReceive.aspx" method="post">
First name: <input type="text" name="fname"><br>
Last name: <input type="text" name="lname"><br>
<input type="submit" value="Submit">
</form>
</body>
</html>
在 web 应用程序 2(接收器)中,我有这个 TestCrossDomainReceive.aspx(那里什么都没有):
<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="TestCrossDomainReceive.aspx.cs" Inherits="WebApplication14.TestCrossDomainReceive" %>
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title></title>
</head>
<body>
<form id="form1" runat="server">
<div>
</div>
</form>
</body>
</html>
和TestCrossDomainReceive.aspx.cs:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
namespace WebApplication14
{
public partial class TestCrossDomainReceive : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
string fname = Request.Form["fname"];
string lname = Request.Form["lname"];
}
}
}
当我在Page_Load 中设置调试点时,fname 和lname 永远是null
我在这里想念什么?我已经调试了两天...
【问题讨论】:
-
我无法复制。复制您的代码完全按预期工作。你能提供更多细节吗?
-
@MikeSmithDev 我修改了问题。这正是我使用的;对于实际使用的端口号,请更改为本地计算机上的任何内容。谢谢!
-
请同时附上您的
.aspx代码。 -
好的。那么在 POST 之后,当断点在 lname 上时,fname 的值是多少? (当断点在 fname 上时,该值尚未设置,所以是的,它将为空)。
-
值为空。一件奇怪的事情,在断点处,它显示 Request.RequestType 是“GET”,Request.HttpMethod 是“GET”。但我在发件人中设置了“post”
标签: c# asp.net cross-domain forms http-post