繁体   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