private List <string> BaiduSearch(string baseKeyword, string userAgent) { string suggestionUrl = "http://suggestion.baidu.com/su?wd=" + baseKeyword + "&cb=window.bdsug.sug&from=superpage&t=1335581987353"; List <string> result = null; HttpHelper.HttpParam hp = new HttpHelper.HttpParam() { URL = suggestionUrl, UserAgent = userAgent, ContentType = "application/json;charset=unicode", Timeout = TimeSpan.FromSeconds(1), Method = HttpHelper.HttpVerb.Get, AllowAutoRedirect = false, Accept = "*/*", Referer = "http://www.baidu.com/", }; HttpHelper.HttpResult hr = HttpHelper.Request(hp); if (hr.Result != null) { var sr = new StreamReader(hr.Result, Encoding.Default); if (sr != null) { string html = sr.ReadToEnd(); if (!string.IsNullOrEmpty(html)) { ParserBaiduSearchResult(html, out result); } } hr.Result.Close(); } return(result); }
private TaskGroup_FileCheck_OneData ScanRequestGetBody(string url, string userAgent) { Stopwatch st = new Stopwatch(); st.Start(); TaskGroup_FileCheck_OneData result = new TaskGroup_FileCheck_OneData(url); HttpHelper.HttpParam hp = new HttpHelper.HttpParam() { URL = url, UserAgent = userAgent, ContentType = "application/json;charset=unicode", Timeout = TimeSpan.FromSeconds(1), Method = HttpHelper.HttpVerb.Get, AllowAutoRedirect = false, Accept = "*/*", Referer = "http://www.baidu.com/", }; HttpHelper.HttpResult hr = HttpHelper.Request(hp); if (hr.Result != null) { result.contentType = hr.ContentType; result.length = hr.ContentLength; result.server = hr.Server; result.code = (int)hr.StatusCode; result.powerBy = hr.Header.Get("X-Powered-By"); } result.time = st.ElapsedMilliseconds; return(result); }
private List <string> BaiduSearch(string keyword, string userAgent) { string url = "http://www.baidu.com/s?ie=utf-8&wd=" + keyword + "&rn=50"; //GlobalVar.Instance.logger.Debug("Ready to search : " + url); List <string> result = null; HttpHelper.HttpParam hp = new HttpHelper.HttpParam() { URL = url, UserAgent = userAgent, ContentType = "application/json;charset=unicode", Timeout = TimeSpan.FromSeconds(1), Method = HttpHelper.HttpVerb.Get, AllowAutoRedirect = false, Accept = "*/*", Referer = "http://www.baidu.com/", }; HttpHelper.HttpResult hr = HttpHelper.Request(hp); if (hr.Result != null) { var sr = new StreamReader(hr.Result, Encoding.Default); if (sr != null) { string html = sr.ReadToEnd(); if (!string.IsNullOrEmpty(html)) { //GlobalVar.Instance.logger.Debug("HTML length = " + html.Length); ParserBaiduSearchResult(html, out result); } } hr.Result.Close(); } return(result); }
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 sync_upload() { 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 + "/hello2.txt"; File.WriteAllText(file, "hellp upload.上传内容."); var r = HttpHelper.Request(param, new[] { new HttpHelper.NamedFileStream("t1", "hello2.txt", File.OpenRead(file)) }); File.Delete(file); var sr = new StreamReader(r.Result); Console.WriteLine("sync_upload \n" + sr.ReadToEnd()); r.Result.Close(); }
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(); }