public override void Execute() { head_test(); get_test(); post_test(); put_test(); delete_test(); patch_test(); //测试timeout var param = new HttpHelper.HttpParam(); param.Timeout = TimeSpan.FromSeconds(3); param.URL = "http://192.168.0.133:8002"; param.Header = new System.Net.WebHeaderCollection(); param.Header.Add("X_FORWARDED_FOR", "20.3.2.8"); var rtl = HttpHelper.Request(param); body_test(); upload_test(); err_test(); }
void sync_body() { HttpHelper.HttpParam param = new HttpHelper.HttpParam(); param.URL = "http://localhost:3982/api/share"; param.Method = HttpHelper.HttpVerb.Post; param.ContentType = "text/json"; var json = "{\"Name\":\"JohnWu\",\"Age\":12}"; MemoryStream ms = new MemoryStream(Encoding.UTF8.GetBytes(json)); var r = HttpHelper.Request(param, ms); var sr = new StreamReader(r.Result); Console.WriteLine("sync_body \n" + sr.ReadToEnd()); r.Result.Close(); }
void uploadTest() { HttpHelper.HttpParam param = new HttpHelper.HttpParam(); param.URL = "http://localhost:3982/home/upload"; param.Method = HttpHelper.HttpVerb.Post; param.Parameters = new { name = "提交文件内容", age = 23 }; var file = AppDomain.CurrentDomain.BaseDirectory + "/hello.txt"; File.WriteAllText(file, "hellp upload.上传内容."); HttpHelper.Request(param, new[] { new HttpHelper.NamedFileStream("t1", "hello.txt", File.OpenRead(file)) }, callback: (r) => { File.Delete(file); var sr = new StreamReader(r.Result); Console.WriteLine("uploadTest \n" + sr.ReadToEnd()); r.Result.Close(); }); }