【问题标题】:Request in C# Not working? [closed]C# 中的请求不起作用? [关闭]
【发布时间】:2015-04-22 15:40:06
【问题描述】:

您好,我希望使用标头将统一项目中的值推送到 ASPX 字符串中。我想知道如何做到这一点。我可以在 PHP 中使用简单的 $_Request(ID) 来完成,然后使用类似

using UnityEngine;
using System.Collections;

public class NewSession : MonoBehaviour {

                string userLoginFile = "http://local/UnitySQL/NewSession.php?UserId=";
                public UnityEngine.UI.Text NewSess;                     

                string userid = "";
                string session = "";

               void OnGUI()
                {
                                session = NewSess.text;
                                userid = PlayerPrefs.GetString ("UserId");
                }



                public void Insert()
                {
                                if (session == "") {
                                                Application.OpenURL (userLoginFile +userid);
                                                //StartCoroutine (LoginUser (userid));
                                } else {
                                                print("DAMNSON");
                                }
                }




                /*IEnumerator LoginUser(string user)
                {

                                WWW login = new WWW (userLoginFile + "UserId=" + user);
                                print (userLoginFile + "UserId=" + user);
                                yield return login;

                                if (login.error == null)
                                {

                                                string[] credentials = login.text.Split('/');

                                                foreach(string str in credentials)
                                                {
                                                                string[] creds = str.Split ('=');

                                                                for(int i=0; i < creds.Length; i++)
                                                                {
                                                                                print ("winner");
                                                                }


                                                }
                                }

                }*/
}

Then the PHP would just be a simple 
                $userid = $_REQUEST['UserId'];

UID = $_REQUEST(ID);

我想知道如何使用 C# 提前致谢

【问题讨论】:

  • ASPX 字符串是什么意思?您的问题目前写的非常不清楚。
  • 请贴出你写到现在的代码。那么,帮助你就更容易了。

标签: c# asp.net reporting


【解决方案1】:

我认为您想处理 HTTP 请求。看一眼 https://msdn.microsoft.com/en-us/library/system.web.httprequest%28v=vs.110%29.aspx

文档示例:

    public partial class AddToCart : Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        string rawId = Request["ProductID"];
        int productId;
        if (!String.IsNullOrEmpty(rawId) && int.TryParse(rawId, out productId))
        {
            using (ShoppingCartActions usersShoppingCart = new ShoppingCartActions())
            {
                usersShoppingCart.AddToCart(productId);
            }
        }
        else
        {
            throw new Exception("Tried to call AddToCart.aspx without setting a ProductId.");
        }
        Response.Redirect("ShoppingCart.aspx");
    }
}

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2017-02-16
    • 2015-04-30
    • 1970-01-01
    • 1970-01-01
    • 2014-10-04
    • 2016-04-23
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多