예제 #1
0
        public void DoRequest()
        {
            var methord = cbMethord.SelectedItem.ToString();

            if (methord.Equals("post", StringComparison.OrdinalIgnoreCase))
            {
                var rslt = HttpHelper.Instance.PostDataTo(tbUrl.Text,
                                                          tbRequestBody.Text,
                                                          new Dictionary <string, string>()
                {
                    { tbIdKey.Text, tbAppId.Text },
                    { tbAppSecretyKey.Text, PercentEncoding.GenerateSignature(tbUrl.Text, "post", tbRequestBody.Text, tbAppSecurity.Text) }
                }
                                                          );
                tbResult.Text = rslt;
            }
            else
            {
                var rslt = HttpHelper.Instance.GetResponseFrom(tbUrl.Text,
                                                               new Dictionary <string, string>()
                {
                    { tbIdKey.Text, tbAppId.Text },
                    { tbAppSecretyKey.Text, PercentEncoding.GenerateSignature(tbUrl.Text, "get", "", tbAppSecurity.Text) }
                }
                                                               );
                tbResult.Text = rslt;
            }
        }
예제 #2
0
        public void UploadFile()
        {
            using (var client = new HttpClient())
            {
                var fileName = tbFilePath.Text;
                var strUrl   = tbUrl.Text;
                client.DefaultHeaders.Add(tbIdKey.Text, tbAppId.Text);
                var sign = PercentEncoding.GenerateSignature(tbUrl.Text, "post", GetFileBase64(), tbAppSecurity.Text);
                client.DefaultHeaders.Add(tbAppSecretyKey.Text, sign);

                var content = HttpContent.Create(File.OpenRead(fileName));
                try
                {
                    var response = client.Post(strUrl, content);
                    response.EnsureStatusIsSuccessful();
                    var readResult = response.Content.ReadAsString();
                    tbResult.Text = readResult;
                }
                catch (Exception exp)
                {
                    tbResult.Text = exp.Message;
                }
                finally
                {
                    content.Dispose();
                }
            }
        }