private void bt_send_Click(object sender, EventArgs e) { List <KeyValuePair <string, string> > myHeads = new List <KeyValuePair <string, string> >(); if (ck_isSgin.Checked) { tb_sendTime.Text = ((DateTime.Now.ToUniversalTime().Ticks - 621355968000000000) / 10000).ToString(); string sginOrginStr = string.Format("appSecret={0}&sendTime={1}", app_secret, tb_sendTime.Text); tb_sign.Text = MyEncryption.CreateMD5Key(sginOrginStr).ToLower(); myHeads.Add(new KeyValuePair <string, string>("Content-type", "application/json;charset=UTF-8")); myHeads.Add(new KeyValuePair <string, string>("Authorization", "bearer " + tb_access_token.Text)); myHeads.Add(new KeyValuePair <string, string>("sign", tb_sign.Text)); myHeads.Add(new KeyValuePair <string, string>("sendTime", tb_sendTime.Text)); myHeads.Add(new KeyValuePair <string, string>("User-Agent", "Tester")); } //<Api name="api">rtb_sendBody.Text.Replace(" "," ")</Api> Stopwatch sw = new Stopwatch(); sw.Start(); string response = myHttp.SendData(string.Format("{0}{1}", tb_host.Text, tb_url.Text), rtb_sendBody.Text, cb_httpMethod.Text, myHeads); if (nowNode != null) { nowNode.InnerText = rtb_sendBody.Text; } sw.Stop(); rtb_response.AddDate(string.Format("耗时:{0} ms", sw.ElapsedMilliseconds), Color.BlueViolet, true); rtb_response.AddDate(response, (response.StartsWith("Error:")) ? Color.Red : Color.Black, true); }
/// <summary> /// 生成Vanelife协议数据 /// </summary> /// <param name="testData">用例数据</param> /// <returns>协议数据</returns> /// private string CreatVanelifeSendData(string testData) { Hashtable myDataTable = new Hashtable(); StringBuilder myStrBld = new StringBuilder(); string tempSign = ""; #region 填装数据 string[] sArray = testData.Split('&'); if (testData == "") { //do nothing } else { foreach (string tempStr in sArray) { int myBreak = tempStr.IndexOf('='); if (myBreak == -1) { return("can't find ="); } myDataTable.Add(tempStr.Substring(0, myBreak), tempStr.Substring(myBreak + 1)); } } myDataTable.Add("key", myExecutionDeviceInfo.dev_key); myDataTable.Add("timestamp", DateTime.Now.ToString("yyyy-MM-ddTHH:mm:ss")); #endregion #region 生成Sign ArrayList akeys = new ArrayList(myDataTable.Keys); akeys.Sort(); foreach (string tempKey in akeys) { myStrBld.Append(tempKey + myDataTable[tempKey]); } myStrBld.Append(myExecutionDeviceInfo.dev_secret); tempSign = MyEncryption.CreateMD5Key(myStrBld.ToString()); #endregion #region 组合数据 myStrBld.Remove(0, myStrBld.Length); //change here myStrBld.Append("signature=" + tempSign); foreach (DictionaryEntry de in myDataTable) { //对每次参数进行url编码 myStrBld.Append("&" + de.Key + "=" + System.Web.HttpUtility.UrlEncode((de.Value).ToString())); } return(myStrBld.ToString()); #endregion }