簡體   English   中英

在跨網域發布中,Request.Form [x]值為null

[英]Request.Form[x] values are null in a Cross-domain Post

我在這里閱讀了有關跨域發布的問題和答案,但仍然無法使它正常工作。 任務看起來很簡單,但是我從接收方獲得的數據始終為空。

在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設置調試點時, fnamelname永遠為null

我在這里想念什么? 我已經調試了兩天...

出於安全原因,瀏覽器通常會阻止您執行此操作。 你可以:

  1. 如果您可以控制目標方法,則將其轉換為處理“ GET”,然后將POST更改為源域上的GET。

  2. POST到源域上的代理服務,然后讓代理將POST傳遞到目標域。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM