简体   繁体   English

如何将数据从ASPX发送到PHP页面

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

so far i have used this code.It is working when i am sending the data from aspx to aspx. 到目前为止,我已经使用了这段代码。当我将数据从aspx发送到aspx时,它可以正常工作。

But in case of aspx to php it is not working..... 但是,如果将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();
    }
}

In case of php i have use this code: 如果是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>

My aim is i want to send data from aspx to php not in the query string. 我的目的是我想将数据从aspx发送到php而不是查询字符串中。

Modify your php script to contain the below given code and see if it works. 修改您的php脚本以包含以下给定的代码,并查看其是否有效。 You don't need anything else apart from the given two lines. 除了给定的两行之外,您不需要其他任何内容。

<?php

print_r($_POST);

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

Interesting... 有趣...

in the onload function, you are calling formload(), which is a server side function , isn't it? 在onload函数中,您正在调用作为服务器端函数的formload(),不是吗?

this is not correct, on client site you should only call client site javascript function. 这是不正确的,在客户端站点上只能调用客户端站点的javascript函数。

if you want to post information to another server, no matter it is php/asp.net/jsp. 如果您想将信息发布到另一台服务器,无论它是php / asp.net / jsp。

simply use a form.... 只需使用表格即可。

in the Post function of your remotepost class, you didn't post to your remote server... just generate some html tags, and in the page load function, submit the form automatically, 在remotepost类的Post函数中,您没有发布到远程服务器...只是生成了一些html标签,而在页面加载函数中,则自动提交了表单,

it is not nice, but should work. 这不是很好,但应该可以。

correct first issue first, then see how it goes. 首先更正第一个问题,然后查看进展如何。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM