Пример #1
0
        public void HttpPostWithParameters2()
        {
            HttpClient client = new HttpClient();

            // first request - to get cookies
            HttpGet      getMethod = new HttpGet(new Uri(Constants.HTTP_POST_W3SCHOOLS));
            HttpResponse response  = client.Execute(getMethod);

            Assert.AreEqual(200, response.ResponseCode);

            // second request - to send form data
            HttpPost             postMethod        = new HttpPost(new Uri(Constants.HTTP_POST_W3SCHOOLS));
            List <NameValuePair> nameValuePairList = new List <NameValuePair>();

            nameValuePairList.Add(new NameValuePair("fname", "user 1"));
            UrlEncodedFormEntity formEntity = new UrlEncodedFormEntity(nameValuePairList, Encoding.UTF8);

            postMethod.Entity = formEntity;
            response          = client.Execute(postMethod);

            Assert.AreEqual(200, response.ResponseCode);
            string responseString = EntityUtils.ToString(response.Entity);

            Assert.IsTrue(responseString.Contains("Hello user 1!"));
        }
Пример #2
0
        protected UrlEncodedFormEntity CreateFormBody <T>(T entity) where T : BaseParameter
        {
            var kvc    = ResolveParameter(entity);
            var result = new UrlEncodedFormEntity(kvc.Select(r => new NameValuePair(r.Key, r.Value)).ToList(), Encoding.Default);

            return(result);
        }
Пример #3
0
        public void Send()
        {
            HttpClient client     = new HttpClient();
            HttpPost   postMethod = new HttpPost(new Uri("http://sendcloud.sohu.com/webapi/label.create.json"));

            //MultipartEntity multipartEntity = new MultipartEntity();
            //multipartEntity.AddBody(new StringBody(Encoding.UTF8, "api_user", ""));
            //multipartEntity.AddBody(new StringBody(Encoding.UTF8, "api_key", ""));
            //multipartEntity.AddBody(new StringBody(Encoding.UTF8, "labelName", "hhLabel"));


            UrlEncodedFormEntity urlFormEntity = new UrlEncodedFormEntity(new List <NameValuePair>()
            {
                new NameValuePair()
                {
                    Name = "api_user", Value = ""
                },
                new NameValuePair()
                {
                    Name = "api_key", Value = ""
                },
                new NameValuePair()
                {
                    Name = "labelName", Value = ""
                }
            }, Encoding.UTF8);

            postMethod.Entity = urlFormEntity;

            HttpResponse response = client.Execute(postMethod);

            Console.WriteLine("Response Code: " + response.ResponseCode);
            Console.WriteLine("Response Content: " + EntityUtils.ToString(response.Entity));
        }
Пример #4
0
        public static string sendPost(String Url, List <NameValuePair> nameValuePairList)
        {
            HttpClient client     = new HttpClient();
            HttpPost   postMethod = new HttpPost(new Uri(Url));

            UrlEncodedFormEntity formEntity = new UrlEncodedFormEntity(nameValuePairList, Encoding.UTF8);

            postMethod.Entity = formEntity;

            HttpResponse response = client.Execute(postMethod);

            Console.WriteLine("Response Code: " + response.ResponseCode);
            Console.WriteLine("Response Content: " + EntityUtils.ToString(response.Entity));


            return(EntityUtils.ToString(response.Entity));
        }
Пример #5
0
        public static void DoPost()
        {
            HttpClient client     = new HttpClient();
            HttpPost   postMethod = new HttpPost(new Uri("http://www.w3schools.com/asp/demo_simpleform.asp"));

            List <NameValuePair> nameValuePairList = new List <NameValuePair>();

            nameValuePairList.Add(new NameValuePair("fname", "brian"));

            UrlEncodedFormEntity formEntity = new UrlEncodedFormEntity(nameValuePairList, Encoding.UTF8);

            postMethod.Entity = formEntity;

            HttpResponse response = client.Execute(postMethod);

            Console.WriteLine("Response Code: " + response.ResponseCode);
            Console.WriteLine("Response Content: " + EntityUtils.ToString(response.Entity));
        }
Пример #6
0
        public static void DoPost()
        {
            /*
             * HttpClient client = new HttpClient();
             * HttpPost postMethod = new HttpPost(new Uri("http://www.w3schools.com/asp/demo_simpleform.asp"));
             *
             * List<NameValuePair> nameValuePairList = new List<NameValuePair>();
             * nameValuePairList.Add(new NameValuePair("fname", "brian"));
             *
             * UrlEncodedFormEntity formEntity = new UrlEncodedFormEntity(nameValuePairList, Encoding.UTF8);
             * postMethod.Entity = formEntity;
             *
             * HttpResponse response = client.Execute(postMethod);
             *
             * Console.WriteLine("Response Code: " + response.ResponseCode);
             * Console.WriteLine("Response Content: " + EntityUtils.ToString(response.Entity));
             */

            HttpClient client = new HttpClient();

            client.Timeout = 10000;
            HttpPost postMethod = new HttpPost(new Uri("http://tmobilebilling.changyou.com/billing"));

            postMethod.Headers.Add("appkey", "1407921103977");
            postMethod.Headers.Add("sign", "51e912635a5b5350");
            postMethod.Headers.Add("tag", "7911376");
            postMethod.Headers.Add("opcode", "10001");
            postMethod.Headers.Add("channelId", "4001");

            List <NameValuePair> nameValuePairList = new List <NameValuePair>();

            nameValuePairList.Add(new NameValuePair("data", "{\"validateInfo\":\"50d2f67deb4b7ba881c130ee401997b098ff53568703b5c4af095530e98f79dc5d273a851db2d6208aa1bbc5873f7b731e3999cb6bf6607544bf8c2cbb5dc114838857023a62ca07c4eb355fb4b1fa9482e22a55b3a5ce8c2b678bfe24627963719442d2ecf2a8a89e95b28ec819f4dd5bad82be017b13b5051dc7387f5570ae182f60962c4b54cba4b4eb9c83e8027cc08cb4281921ebda3fbf4d8bb14a85767a449420e07b72c86eb584ee1b1b88516e4bd4ef9c487a7bcb036229ae5400c9e79ff6318d0722c94203b17fd43f50dc\"}"));

            UrlEncodedFormEntity formEntity = new UrlEncodedFormEntity(nameValuePairList, Encoding.UTF8);

            postMethod.Entity = formEntity;

            HttpResponse response    = client.Execute(postMethod);
            string       responseStr = EntityUtils.ToString(response.Entity);

            Console.WriteLine(responseStr);
        }
Пример #7
0
        public void HttpPost()
        {
            HttpClient           client            = new HttpClient();
            HttpPost             postMethod        = new HttpPost(new Uri(Constants.HTTP_POST_200));
            List <NameValuePair> nameValuePairList = new List <NameValuePair>();

            nameValuePairList.Add(new NameValuePair("param1", "value1"));
            nameValuePairList.Add(new NameValuePair("param2", "!#$^&*((<>"));
            UrlEncodedFormEntity formEntity = new UrlEncodedFormEntity(nameValuePairList, Encoding.UTF8);

            postMethod.Entity = formEntity;
            HttpResponse response = client.Execute(postMethod);

            Assert.AreEqual(200, response.ResponseCode);
            string      responseString = EntityUtils.ToString(response.Entity);
            MessageData md             = new MessageData();

            md.PostParameters.Add(new NameValuePair("param1", "value1"));
            md.PostParameters.Add(new NameValuePair("param2", "!#$^&*((<>"));
            Assert.AreEqual(md.ToString(), responseString);
            Assert.AreEqual(Constants.HTTP_POST_200, response.RequestUri.AbsoluteUri);
            Console.Write(responseString);
        }
Пример #8
0
    private void VerifyAccountWorker(LB_VerifyAccount msg, PBChannel channel)
    {
        try
        {
            int    tag       = CreateTag();
            string signParam = string.Format("{0}{1}{2}{3}{4}{5}", msg.OpCode, msg.Data, m_AppKey, m_AppSecret, tag, msg.ChannelId);
            string sign      = CreateSign(signParam);

            HttpClient client = new HttpClient();
            client.Timeout = m_HttpRequestTimeout;
            HttpPost postMethod = new HttpPost(new Uri(m_TestBillingServerUrl));

            postMethod.Headers.Add("appkey", m_AppKey);
            postMethod.Headers.Add("sign", sign);
            postMethod.Headers.Add("tag", tag.ToString());
            postMethod.Headers.Add("opcode", msg.OpCode.ToString());
            postMethod.Headers.Add("channelId", msg.ChannelId.ToString());

            List <NameValuePair> nameValuePairList = new List <NameValuePair>();
            nameValuePairList.Add(new NameValuePair("data", msg.Data));

            UrlEncodedFormEntity formEntity = new UrlEncodedFormEntity(nameValuePairList, Encoding.UTF8);
            postMethod.Entity = formEntity;

            LogSys.Log(LOG_TYPE.INFO, "Account:{0}, HttpPost headers. appkey:{1}, sign:{2}, tag:{3}, opcode:{4}, channelId:{5}",
                       msg.Account, m_AppKey, sign, tag, msg.OpCode, msg.ChannelId);
            LogSys.Log(LOG_TYPE.INFO, "Account:{0}, HttpPost parameters. data:{1}", msg.Account, msg.Data);
            //============================================

            HttpResponse response    = client.Execute(postMethod);
            string       responseStr = EntityUtils.ToString(response.Entity);

            DestroyTag(tag);

            //==================================================
            LogSys.Log(LOG_TYPE.INFO, "Account:{0}, Response:{1}", msg.Account, responseStr);
            //==================================================

            JsonVerifyAccountResult result = JsonConvert.DeserializeObject(responseStr, typeof(JsonVerifyAccountResult)) as JsonVerifyAccountResult;
            var reply = BL_VerifyAccountResult.CreateBuilder();
            reply.Account   = msg.Account;
            reply.OpCode    = result.opcode;
            reply.ChannelId = result.channelId;
            reply.AccountId = "";
            reply.Result    = false;
            int repState = result.state;
            if (repState == (int)BillingRepState.Success && result.data != null)
            {
                int status = int.Parse(result.data.status);
                if (status == 1 && result.channelId == msg.ChannelId && result.opcode == msg.OpCode)
                {
                    reply.AccountId = result.data.userid;
                    reply.Result    = true;
                }
            }
            if (reply.Result == true)
            {
                LogSys.Log(LOG_TYPE.INFO, ConsoleColor.Green, "Account verify success. Account:{0} ID:{1}", reply.Account, reply.AccountId);
            }
            else
            {
                LogSys.Log(LOG_TYPE.INFO, ConsoleColor.Yellow, "Account verify failed. Account:{0} Msg:{1}", reply.Account, result.error);
            }
            channel.Send(reply.Build());
        }
        catch (Exception ex)
        {
            LogSys.Log(LOG_TYPE.ERROR, ConsoleColor.Red, "Exception Type:{0}", ex.GetType().ToString());
            LogSys.Log(LOG_TYPE.ERROR, ConsoleColor.Red, "Exception:{0}\n{1}", ex.Message, ex.StackTrace);
        }
    }
Пример #9
0
        private void doSubmit(String submitType, String emptyString, String statusString)
        {
            var container = new PojoWarningContainer();

            container.TunnelId = _inInfo.TunnelId;


            var warnings = new Dictionary <string, PojoWarning>();

            for (var i = FROZEN_ROW_COUNT; i < _fpPreWarningResultDetials.ActiveSheet.RowCount; i++)
            {
                var detail = new PojoWarningDetail();
                detail.Id = cells[i, COLUMN_INDEX_HIDE_DATA_ID].Text;


                switch (submitType)
                {
                case "Actions":
                {
                    detail.Actions         = cells[i, COLUMN_INDEX_ACTIONS].Text;
                    detail.ActionsPerson   = ConfigManager.Instance.getValueByKey(ConfigConst.CONFIG_CURRENT_USER);
                    detail.ActionsDateTime = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss");
                    break;
                }

                case "Comments":
                {
                    detail.Actions          = cells[i, COLUMN_INDEX_ACTIONS].Text;
                    detail.Comments         = cells[i, COLUMN_INDEX_COMMENTS].Text;
                    detail.CommentsPerson   = ConfigManager.Instance.getValueByKey(ConfigConst.CONFIG_CURRENT_USER);
                    detail.CommentsDateTime = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss");
                    break;
                }

                case "WarningLift":
                {
                    detail.Actions      = cells[i, COLUMN_INDEX_ACTIONS].Text;
                    detail.Comments     = cells[i, COLUMN_INDEX_COMMENTS].Text;
                    detail.LiftPerson   = ConfigManager.Instance.getValueByKey(ConfigConst.CONFIG_CURRENT_USER);
                    detail.LiftDateTime = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss");
                    break;
                }
                }

                detail.RuleId = warningResultDetails.Find(u => u.Id == detail.Id).RuleId;
                detail.DataId = warningResultDetails.Find(u => u.Id == detail.Id).DataId;

                var warningId = cells[i, COLUMN_INDEX_HIDE_WARNING_ID].Text;

                PojoWarning warning = null;
                if (warnings.ContainsKey(warningId))
                {
                    warning = warnings[warningId];
                }
                else
                {
                    warning           = new PojoWarning();
                    warning.WarningId = warningId;
                    warnings.Add(warningId, warning);
                }

                warning.addDetail(detail);

                switch (submitType)
                {
                case "Actions":
                {
                    if (isEmptyString(detail.Actions))
                    {
                        MessageBox.Show(emptyString);
                        return;
                    }
                    break;
                }

                case "Comments":
                {
                    if (isEmptyString(detail.Comments))
                    {
                        MessageBox.Show(emptyString);
                        return;
                    }
                    break;
                }

                case "WarningLift":
                {
                    break;
                }
                }
            }

            foreach (var pair in warnings)
            {
                container.addWarning(pair.Value);
            }

            var client1    = new HttpClient();
            var postMethod =
                new HttpPost(
                    new Uri("http://" + serverIp + ":" + restPort + "/rest/tunnels/" + _inInfo.TunnelId + "/warninglift"));
            var nameValuePairList = new List <NameValuePair>();

            switch (submitType)
            {
            case "Actions":
            {
                nameValuePairList.Add(new NameValuePair(OPERATION, OPERATION_ACTION));     // 采取措施
                break;
            }

            case "Comments":
            {
                nameValuePairList.Add(new NameValuePair(OPERATION, OPERATION_COMMENTS));     // 采取措施
                break;
            }

            case "WarningLift":
            {
                nameValuePairList.Add(new NameValuePair(OPERATION, OPERATION_WARNING_LIFT));     // 采取措施
                break;
            }
            }
            //nameValuePairList.Add(new NameValuePair(OPERATION, OPERATION_ACTION)); // 采取措施
            var jsonStr = JsonConvert.SerializeObject(container); // 措施详细描述

            nameValuePairList.Add(new NameValuePair(Const.JSON_MSG, jsonStr));
            var formEntity = new UrlEncodedFormEntity(nameValuePairList, Encoding.UTF8);

            postMethod.Entity = formEntity;

            var response = client1.Execute(postMethod);

            var responseCode = response.ResponseCode;

            if (responseCode < 400)
            {
                MessageBox.Show("提交成功!" + Encoding.UTF8.GetString(response.Entity.Content));
                lblStatus.Text  = statusString;
                btnDoIt.Enabled = false;
            }
            else
            {
                MessageBox.Show("提交失败,请检查是否和服务器正常连接!");
            }
        }