簡體   English   中英

如何將數據從ASPX發送到PHP頁面

[英]How to send data from aspx to php page

到目前為止,我已經使用了這段代碼。當我將數據從aspx發送到aspx時,它可以正常工作。

但是,如果將aspx轉換為php,則無法正常工作.....

protected void Button1_Click(object sender, EventArgs e)
{
    RemotePost myremotepost = new RemotePost();
    myremotepost.Url = "http://172.16.126.32/Riyas/marggroup.com/get-current-openings.php";
    myremotepost.Add("field1", TextBox1.Text);
    myremotepost.Post();
}
public class RemotePost
{
    private System.Collections.Specialized.NameValueCollection Inputs = new System.Collections.Specialized.NameValueCollection();


    public string Url = "";
    public string Method = "post";
    public string FormName = "form1";

    public void Add(string name, string value)
    {
        Inputs.Add(name, value);
    }

    public void Post()
    {
        System.Web.HttpContext.Current.Response.Clear();

        System.Web.HttpContext.Current.Response.Write("<html><head>");

        System.Web.HttpContext.Current.Response.Write(string.Format("</head><body onload=\"document.{0}.submit()\">", FormName));
        System.Web.HttpContext.Current.Response.Write(string.Format("<form name=\"{0}\" method=\"{1}\" action=\"{2}\" >", FormName, Method, Url));
        for (int i = 0; i < Inputs.Keys.Count; i++)
        {
            System.Web.HttpContext.Current.Response.Write(string.Format("<input name=\"{0}\" type=\"hidden\" value=\"{1}\">", Inputs.Keys[i], Inputs[Inputs.Keys[i]]));
        }
        System.Web.HttpContext.Current.Response.Write("</form>");
        System.Web.HttpContext.Current.Response.Write("</body></html>");

        System.Web.HttpContext.Current.Response.End();
    }
}

如果是php,我已經使用以下代碼:

<script runat="server">

    function formload()
    {
         alert("its working");  
        if(Request.Form["field1"] != null ){
            alert("its working");
            Response.Write("field1 : " + Request.Form["field1"] + "</br>");
        }
        if(Request.Form["field2"] != null ){
            Response.Write("field2 : " +Request.Form["field2"] + "</br>");
        }
    }
    </script>
    </head>
<body onload="JavaScript:formload()">
<script language="JavaScript">// change to text/javascript or even remove, no effect
window.onload = function() {
  formload();
};
</script>
</body>

我的目的是我想將數據從aspx發送到php而不是查詢字符串中。

修改您的php腳本以包含以下給定的代碼,並查看其是否有效。 除了給定的兩行之外,您不需要其他任何內容。

<?php

print_r($_POST);

如果不在查詢字符串中,為什么不將其作為POST數據發送呢?

有趣...

在onload函數中,您正在調用作為服務器端函數的formload(),不是嗎?

這是不正確的,在客戶端站點上只能調用客戶端站點的javascript函數。

如果您想將信息發布到另一台服務器,無論它是php / asp.net / jsp。

只需使用表格即可。

在remotepost類的Post函數中,您沒有發布到遠程服務器...只是生成了一些html標簽,而在頁面加載函數中,則自動提交了表單,

這不是很好,但應該可以。

首先更正第一個問題,然后查看進展如何。

暫無
暫無

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

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