public void HttpPostTest()
        {
            string s;
            bool   b = false;

            //测试用例1
            s = RestSharpHelper.HttpPost((string)null, (string)null, (Dictionary <string, object>)null,
                                         out b, (Dictionary <string, object>)null,
                                         (Dictionary <string, string>)null, (object)null);
            Assert.AreEqual <bool>(false, b);
            //测试用例2
            s = RestSharpHelper.HttpPost("", (string)null, (Dictionary <string, object>)null,
                                         out b, (Dictionary <string, object>)null,
                                         (Dictionary <string, string>)null, (object)null);
            Assert.AreEqual <bool>(false, b);

            //测试用例3
            s = RestSharpHelper.HttpPost(":xn--%\0\0", (string)null, (Dictionary <string, object>)null,
                                         out b, (Dictionary <string, object>)null,
                                         (Dictionary <string, string>)null, (object)null);
            Assert.AreEqual <bool>(false, b);
            //测试用例4
            s = RestSharpHelper.HttpPost("/\\/", (string)null, (Dictionary <string, object>)null,
                                         out b, (Dictionary <string, object>)null,
                                         (Dictionary <string, string>)null, (object)null);
            Assert.AreEqual <bool>(false, b);
            //测试用例5
            s = RestSharpHelper.HttpPost("\0\0:", (string)null, (Dictionary <string, object>)null,
                                         out b, (Dictionary <string, object>)null,
                                         (Dictionary <string, string>)null, (object)null);
            Assert.AreEqual <bool>(false, b);
            //测试用例6
            s = RestSharpHelper.HttpPost("x0: ", (string)null, (Dictionary <string, object>)null,
                                         out b, (Dictionary <string, object>)null,
                                         (Dictionary <string, string>)null, (object)null);
            Assert.AreEqual <bool>(true, b);
        }
Пример #2
0
 protected void ExecutePost(
     Dictionary <string, object> parameterDict,
     EventHandler <ServiceEventArgs> callbackFunc,
     Dictionary <string, object> fileDict   = null,
     Dictionary <string, string> headerDict = null,
     object entity = null)
 {
     Task task = Task.Factory.StartNew(() =>
     {
         bool iss       = false;
         string content = "";
         BaseResultInfo <object> result = null;
         try
         {
             content = RestSharpHelper.HttpPost(this.m_Url, this.m_Resource, parameterDict, out iss, fileDict, headerDict, entity);
             result  = JsonHelper.JSONToObject <BaseResultInfo <object> >(content);
             if (callbackFunc != null)
             {
                 if (result != null)
                 {
                     callbackFunc(this, new ServiceEventArgs(content, result.status == 10000)
                     {
                         OriginObject   = entity,
                         Message        = result.msg,
                         ResponseObject = result
                     });
                 }
                 else
                 {
                     callbackFunc(this, new ServiceEventArgs(content, false)
                     {
                         OriginObject = entity,
                         Message      = "解析json(BaseResultInfo<object>)失败!",
                     });
                 }
             }
         }
         catch (Exception ex)
         {
             if (callbackFunc != null)
             {
                 if (result != null)
                 {
                     callbackFunc(this, new ServiceEventArgs(content, result.status == 10000)
                     {
                         OriginObject   = entity,
                         Message        = string.Format("Response:{0}\r\n{1}\r\n{2}", content, ex.Message, ex.StackTrace),
                         ResponseObject = result
                     });
                 }
                 else
                 {
                     callbackFunc(this, new ServiceEventArgs(content, false)
                     {
                         OriginObject = entity,
                         Message      = string.Format("Response:{0}\r\n{1}\r\n{2}", content, ex.Message, ex.StackTrace),
                     });
                 }
             }
         }
     });
 }