如何从aspx发送数据到php页面

本文关键字:数据 php 页面 aspx | 更新日期: 2023-09-27 18:18:44

到目前为止我已经使用了这段代码。当我从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不在查询字符串

如何从aspx发送数据到php页面

修改您的php脚本,以包含以下给定的代码,看看它是否工作。除了给定的两行,您不需要任何其他内容。

<?php
print_r($_POST);

有趣…

在onload函数中,您正在调用formload(),这是一个服务器端函数,不是吗?

这是不正确的,在客户端站点你应该只调用客户端站点javascript函数。

如果你想发布信息到另一个服务器,不管它是php/asp.net/jsp。

只需使用表单....

在你的remotepost类的Post函数中,你没有发送到你的远程服务器…只需生成一些HTML标签,并在页面加载函数中,自动提交表单,

它不是很好,但应该可以工作。

先纠正第一个问题,然后看看情况如何。

如果不在查询字符串中,为什么不将其作为POST数据发送呢?