Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/196.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# { db_Action.ExecuteSingleQuery(查询,参数); 状态=常量。状态成功插入; } 接住 { STATE=常量。STATE\u DUBLICATE\u调用; 参数Clear(); 参数添加(“@username”,username_C#_Android_Http Post - Fatal编程技术网

C# { db_Action.ExecuteSingleQuery(查询,参数); 状态=常量。状态成功插入; } 接住 { STATE=常量。STATE\u DUBLICATE\u调用; 参数Clear(); 参数添加(“@username”,username

C# { db_Action.ExecuteSingleQuery(查询,参数); 状态=常量。状态成功插入; } 接住 { STATE=常量。STATE\u DUBLICATE\u调用; 参数Clear(); 参数添加(“@username”,username,c#,android,http-post,C#,Android,Http Post,{ db_Action.ExecuteSingleQuery(查询,参数); 状态=常量。状态成功插入; } 接住 { STATE=常量。STATE\u DUBLICATE\u调用; 参数Clear(); 参数添加(“@username”,username); 参数Add(“@code”,appid+“”+pageCode+“”+id+“”+epochetime+“”+)(DateTime.UtcNow-new DateTime(1970,1,1)).TotalSeconds+“”+IP); 参

{ db_Action.ExecuteSingleQuery(查询,参数); 状态=常量。状态成功插入; } 接住 { STATE=常量。STATE\u DUBLICATE\u调用; 参数Clear(); 参数添加(“@username”,username); 参数Add(“@code”,appid+“”+pageCode+“”+id+“”+epochetime+“”+)(DateTime.UtcNow-new DateTime(1970,1,1)).TotalSeconds+“”+IP); 参数Add(“@value”,UserAgent); query=“插入监视器(代码,值)值(@code,@value)”; db_Action.ExecuteSingleQuery(查询,参数); } } } } }
您需要在C#中编写一个完整的Web服务器,或者只在C#中编写一个cgi可执行文件?
main menu\u mobile.aspx
。可能只针对这个活动服务器页面?我的android应用程序将post参数发送到服务器,如上所述,但我不确定服务器端如何读取这些参数。我需要它们用于authentificationyes Main Menu\u mobile.aspx应该读取这些参数并显示您已经拥有的代码。
HttpClient httpclient = new DefaultHttpClient();
    HttpPost httppost = new HttpPost(Server.currentServer + "/mainmenu_mobile.aspx");

    try {
        menuItems = null;

        boolean status = false;
        // Add your data
        List<NameValuePair> nameValuePairs = new ArrayList<NameValuePair>(3);
        nameValuePairs.add(new BasicNameValuePair("auth", Util.Token()));

        nameValuePairs.add(new BasicNameValuePair("AppID", Util.AppID));

        nameValuePairs.add(new BasicNameValuePair("locale", Locale.getDefault().getISO3Language()));

        httppost.setEntity(new UrlEncodedFormEntity(nameValuePairs,"UTF-8"));

        // Execute HTTP Post Request
        HttpResponse response = httpclient.execute(httppost);
        if (response.getStatusLine().getStatusCode() == 200 || response.getStatusLine().getStatusCode() == 201)
        {
            String result = convertStreamToString(response.getEntity().getContent());  

            InputStream inStream = response.getEntity().getContent();

            menuItems = new ArrayList<MenuObject>();

            parser.parse(inStream);     

        }           

        try
        {
            response.getEntity().consumeContent();
        }
        catch (Exception g)
        {

        }

        log.i(response.getStatusLine().getStatusCode()+"");
        status = true;

        return status;

    } catch (ClientProtocolException e) {
        e.printStackTrace();
        // TODO Auto-generated catch block
        return false;
    } catch (IOException e) {
        e.printStackTrace();
        // TODO Auto-generated catch block
        return false;
    }
using ClassLibrary1;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using TiboServer_2;
using System.Data.SqlClient;
using System.Xml;

public partial class mainmenu_mobile : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        Util util = new Util();

        Dictionary<String, String> postParams = util.checkHeader(Request, new String[] { "auth", "AppID", "locale" });

        util.check(Request.UserAgent, constant.PAGECODE_MAINMENU, Request.UserHostAddress);

        if (util.RESPONSE == constant.RESPONSE_ACCESS_GRANTED && util.STATE == constant.STATE_INSERTED_SUCCESFULY)
        {
            Dictionary<string, string> Params = new Dictionary<string, string>();
            Params.Add("@username", util.username);
            Params.Add("@locale", postParams["locale"]);

            String sql = "select title, url, icon, menucode from mobilemenu where locale = '" + postParams["locale"] + "' order by position asc FOR XML RAW ('menu'), ROOT ('mainmenu'), ELEMENTS";

            //xtr.WhitespaceHandling = System.Xml.WhitespaceHandling.None;
            XmlDocument doc = db_Action.getXmlDocument(sql,Params);

            if (doc != null)
            {
                Response.ContentType = "text/xml"; //must be 'text/xml' 
                Response.ContentEncoding = System.Text.Encoding.UTF8; //we'd like UTF-8 
                doc.Save(Response.Output); //save to the text-writer 
            }
        }
        else
        {
            Response.StatusCode = 403;
        }
        Response.End();
    }
}
using System;
using System.Collections.Generic;
using System.Web;
using ClassLibrary1;
using System.Data;
using System.Data.SqlClient;

/// <summary>
/// Summary description for Util
/// </summary>
/// 

namespace TiboServer_2
{
    public class Util
    {  

        //public static String loggingtable = "Server=tcp:jmyvkj5sxx.database.windows.net,1433;Database=tibonalytics_db;User ID=TiboDb@jmyvkj5sxx;Password=Tibo2015;Trusted_Connection=False;Encrypt=True;Connection Timeout=30;";
        public int RESPONSE = constant.RESPONSE_NO_RESPONSE;
        public int STATE = constant.STATE_BEGIN;
        public String username = "";
        public String appid = "-1";
        public String App_id;
        public String token;


        private String passwordkey = "";

        public Dictionary<String,String> checkHeader(HttpRequest Request,String[] Params)
        {
            Dictionary<String, String> postParameters = new Dictionary<String, String>();
            foreach (String param in Params)
            {
                if (Request.Form[param] == null)
                {
                    return null;
                }
                postParameters.Add(param, Request.Form[param]);
            }

            App_id = postParameters["AppID"];
            token = postParameters["auth"];

            return postParameters;
        }
        public Dictionary<String, String> checkHeader(HttpRequest Request, String[] Params,Boolean[] optional)
        {
            Dictionary<String, String> postParameters = new Dictionary<String, String>();
            for(int i=0;i<Params.Length;i++)
            {
                String param = Params[i];
                if (Request.Form[param] == null && !optional[i])
                {
                    return null;
                }
                postParameters.Add(param, Request.Form[param]);
            }

            App_id = postParameters["AppID"];
            token = postParameters["auth"];

            return postParameters;
        }

        public Dictionary<String, String> checkHeader(HttpRequest Request, String[] Params, int[] Validate)
        {
            Dictionary<String, String> postParameters = new Dictionary<String, String>();
            for (int i = 0; i < Params.Length; i++)
            {
                String param = Params[i];
                if (Request.Form[param] == null)
                {
                    return null;
                } 
                else if (Validate[i] == validate.INTEGER)
                {
                    try
                    {
                        Convert.ToInt32(param);
                    }
                    catch
                    {
                        return null;
                    }
                }
                else if (Validate[i] == validate.DOUBLE)
                {
                    try
                    {
                        Convert.ToDouble(param);
                    }
                    catch
                    {
                        return null;
                    }
                }

                postParameters.Add(param, Request.Form[param]);
            }

            App_id = postParameters["AppID"];
            token = postParameters["auth"];

            return postParameters;
        }
        public Dictionary<String, String> checkHeader(HttpRequest Request, String[] Params, int[] Validate,Boolean[] optional)
        {
            Dictionary<String, String> postParameters = new Dictionary<String, String>();
            for (int i = 0; i < Params.Length; i++)
            {
                String param = Params[i];
                if (Request.Form[param] == null && !optional[i])
                {
                    return null;
                }
                else if (Validate[i] == validate.INTEGER)
                {
                    try
                    {
                        Convert.ToInt32(param);
                    }
                    catch
                    {
                        return null;
                    }
                }
                else if (Validate[i] == validate.DOUBLE)
                {
                    try
                    {
                        Convert.ToDouble(param);
                    }
                    catch
                    {
                        return null;
                    }
                }

                postParameters.Add(param, Request.Form[param]);
            }

            App_id = postParameters["AppID"];
            token = postParameters["auth"];

            return postParameters;
        }

        public void check(String UserAgent, int pageCode, String IP)
        {
            Encryption ee = new Encryption();
            String Token = "";

            try
            {
                appid = ee.Decrypt(App_id, constant.AppID_Key);
            }
            catch (Exception f)
            {
                RESPONSE = constant.RESPONSE_UNABLE_TO_DECRYPT_APPID;
                return;
            }

            try
            {
                Token = ee.Decrypt(token, constant.EK);
            }
            catch (Exception f)
            {
                RESPONSE = constant.RESPONSE_UNABLE_TO_DECRYPT_TOKEN;
                return;
            }

            string[] Token_Content = Token.Split(';');

            username = System.Web.HttpUtility.UrlDecode(Token_Content[0].Trim());
            String password = System.Web.HttpUtility.UrlDecode(Token_Content[1].Trim());
            String epochetime = System.Web.HttpUtility.UrlDecode(Token_Content[2].Trim());

            try
            {
                username = ee.Decrypt(username, constant.UsernameKey);
            }
            catch
            {
                RESPONSE = constant.RESPONSE_UNABLE_TO_DECRYPT_USERNAME;
                return;
            }

            try
            {
                epochetime = ee.Decrypt(epochetime, constant.TimeKey);
            }
            catch
            {
                RESPONSE = constant.RESPONSE_UNABLE_TO_DECRYPT_EPOCHTIME;
                return;
            }

            Dictionary<String,String> Params = new Dictionary<String,String>();
            Params.Add("@username", username);

            String query;
            if (appid == "1")
            {
                query = "select videokey,id from login where username = @username and lockaccount = 0";
            }
            else
            {
                query = "select mobilevideokey,id from login where username = @username and lockaccount = 0";
            }

            DataTable dt = db_Action.ExecuteQuery(query, Params);

            if (dt.Rows.Count > 0)
            {
                passwordkey = dt.Rows[0][0].ToString();   //videokey
            }

            long id = (int)dt.Rows[0][1];     //id


            if (username == "promo")
            {
                RESPONSE = constant.RESPONSE_ACCESS_GRANTED;
                STATE = constant.STATE_INSERTED_SUCCESFULY;
            }
            else
            {

                try
                {
                    password = ee.Decrypt(password, passwordkey);
                }
                catch
                {
                    RESPONSE = constant.RESPONSE_UNABLE_TO_DECRYPT_PASSWORD;
                    return;
                }

                RESPONSE = constant.RESPONSE_ACCESS_GRANTED;

                Params.Add("@code",appid + "_" + pageCode + "_" + id + "_" + epochetime);
                String query = "insert into Monitor (code) Values(@code)";


                try
                {
                    db_Action.ExecuteSingleQuery(query, Params);
                    STATE = constant.STATE_INSERTED_SUCCESFULY;
                }
                catch
                {
                    STATE = constant.STATE_DUBLICATE_CALL;
                    Params.Clear();
                    Params.Add("@username", username);
                    Params.Add("@code",  appid + "_" + pageCode + "_" + id + "_" + epochetime + "_" + (DateTime.UtcNow - new DateTime(1970, 1, 1)).TotalSeconds + "_" + IP);
                    Params.Add("@value",UserAgent);
                    query = "insert into Monitor (code,value) Values(@code,@value)";
                    db_Action.ExecuteSingleQuery(query, Params);
                }
            }
        }
    }
}