protected override void Execute(CodeActivityContext context) { System.Net.WebRequest req = System.Net.WebRequest.Create("https://app.pipefy.com/queries"); req.Proxy.Credentials = System.Net.CredentialCache.DefaultNetworkCredentials; req.Timeout = 120000; req.Headers.Add("authorization", "Bearer " + Bearer.Get(context)); req.ContentType = "application/json"; req.Method = "POST"; byte[] bytes = System.Text.Encoding.UTF8.GetBytes("{ \"query\": \"mutation { deleteTable(input: { id: \"" + TableID.Get(context) + "\" }) { success } }\" }"); req.ContentLength = bytes.Length; System.IO.Stream os = req.GetRequestStream(); os.Write(bytes, 0, bytes.Length); os.Close(); System.Net.WebResponse resp = req.GetResponse(); System.IO.StreamReader sr = new System.IO.StreamReader(resp.GetResponseStream()); JArray array = new JArray(); JObject joResponse = JObject.Parse(sr.ReadToEnd()); Return.Set(context, joResponse.ToString()); }
private void backgroundWorker1_DoWork(object sender, DoWorkEventArgs e) { this.backgroundWorker1.ReportProgress(0); //及逆行http请求 HttpHelper http = new HttpHelper(); HttpItem item = new HttpItem() { URL = "https://www.bilibili.com/video/av" + avcode.Text, //URL 必需项 Method = "get", //URL 可选项 默认为Get //ContentType = "text/html",//返回类型 可选项有默认值 ContentType = "application/x-www-form-urlencoded", //返回类型 可选项有默认值 Allowautoredirect = true //默认为False就是不根据重定向自动跳转 }; HttpResult result = http.GetHtml(item); string Html = result.Html; this.backgroundWorker1.ReportProgress(80); //得到html进行匹配图片如果存在则显示 string a = MillentUtil.GetHtmlImageUrlList(Html); if (a == "") { return; } string url = string.Format("http:" + a); System.Net.WebRequest webreq = System.Net.WebRequest.Create(url); System.Net.WebResponse webres = webreq.GetResponse(); using (System.IO.Stream stream = webres.GetResponseStream()) { //解决线程冲突 this.backgroundWorker1.ReportProgress(99); this.Invoke(new MethodInvoker(delegate() { titleimg.Image = Image.FromStream(stream); saveImages.Visible = true; titleimg.Visible = true; })); } }
private string CheckCRL(string serial) { string RestCert = string.Empty; string Service_URL = "http://app.ca.tot.co.th/c_service/verify/product_status_checking_result.jsp"; //ForTEST = 6737 var Parameters = "issuer=null&searchType=serial&sn=" + serial; System.Net.WebRequest req = System.Net.WebRequest.Create(Service_URL); req.ContentType = "application/x-www-form-urlencoded"; req.Method = "POST"; //We need to count how many bytes we're sending. Post'ed Faked Forms should be name=value& byte[] bytes = System.Text.Encoding.ASCII.GetBytes(Parameters); req.ContentLength = bytes.Length; try { System.IO.Stream os = req.GetRequestStream(); os.Write(bytes, 0, bytes.Length); //Push it out there os.Close(); System.Net.WebResponse resp = req.GetResponse(); if (resp != null) { System.IO.StreamReader sr = new System.IO.StreamReader(resp.GetResponseStream(), Encoding.Default); Encoding end = sr.CurrentEncoding; RestCert = sr.ReadToEnd().Trim(); //if (!string.IsNullOrEmpty(RestCert)) //{ // parseHTML(RestCert); //} } } catch (Exception ex) { RestCert = "Error:" + ex.Message; } return(RestCert); }
public string PostWebRequestCustomize(string userid, string passwd, string format, string status, string apiKey) { string usernamePassword = userid + ":" + passwd; string url = "http://api.t.sina.com.cn/statuses/update." + format; string news_title = status; //int news_id = 696365; //string t_news = string.Format("{0},http://news.cnblogs.com/n/{1}/", news_title, news_id); string t_news = news_title; string data = "source=" + apiKey + "&status=" + System.Web.HttpUtility.UrlEncode(t_news); System.Net.WebRequest webRequest = System.Net.WebRequest.Create(url); System.Net.HttpWebRequest httpRequest = webRequest as System.Net.HttpWebRequest; System.Net.CredentialCache myCache = new System.Net.CredentialCache(); myCache.Add(new Uri(url), "Basic", new System.Net.NetworkCredential(userid, passwd)); httpRequest.Credentials = myCache; httpRequest.Headers.Add("Authorization", "Basic " + Convert.ToBase64String(new System.Text.ASCIIEncoding().GetBytes(usernamePassword))); httpRequest.Method = "POST"; httpRequest.ContentType = "application/x-www-form-urlencoded"; System.Text.Encoding encoding = System.Text.Encoding.ASCII; byte[] bytesToPost = encoding.GetBytes(data); httpRequest.ContentLength = bytesToPost.Length; System.IO.Stream requestStream = httpRequest.GetRequestStream(); requestStream.Write(bytesToPost, 0, bytesToPost.Length); requestStream.Close(); string responseContent; System.Net.WebResponse wr = httpRequest.GetResponse(); System.IO.Stream receiveStream = wr.GetResponseStream(); using (System.IO.StreamReader reader = new System.IO.StreamReader(receiveStream, System.Text.Encoding.UTF8)) { responseContent = reader.ReadToEnd(); } return(responseContent); }
/// <summary> /// 下载网页为String /// </summary> /// <param name="Url">网址</param> public static string DownloadWebPage(string Url) { SetAllowUnsafeHeaderParsing(); int testtime = Environment.TickCount; try { // Open a connection System.Net.HttpWebRequest WebRequestObject = (System.Net.HttpWebRequest)System.Net.HttpWebRequest.Create(Url); // You can also specify additional header values like // the user agent or the referer: WebRequestObject.UserAgent = ".NET Framework/2.0"; WebRequestObject.Referer = "http://www.example.com/"; // Request response: System.Net.WebResponse Response = WebRequestObject.GetResponse(); // Open data stream: System.IO.Stream WebStream = Response.GetResponseStream(); // Create reader object: System.IO.StreamReader Reader = new System.IO.StreamReader(WebStream); // Read the entire stream content: string PageContent = Reader.ReadToEnd(); // Cleanup Reader.Close(); WebStream.Close(); Response.Close(); testtime = Environment.TickCount - testtime; return(PageContent); } catch (Exception) { return(null); } }
public static string Send(string mobile, string templateid) { var appSecret = ADVConstants.Settings.SendCode.APP_SECRET.GetValues(); var appKey = ADVConstants.Settings.SendCode.APP_KEY.GetValues(); var url = ADVConstants.Settings.SendCode.APP_URL.GetValues(); TimeSpan ts = DateTime.UtcNow - new DateTime(1970, 1, 1, 0, 0, 0, 0); string nonce = new Random().Next(100000, 999999).ToString(); string curTime = Convert.ToInt64(ts.TotalSeconds).ToString(); string checkSum = SHA1_Hash(appSecret + nonce + curTime); string post = "mobile=" + mobile + "&templateid=" + templateid; byte[] btBodys = Encoding.UTF8.GetBytes(post); System.Net.WebRequest wReq = System.Net.WebRequest.Create(url); wReq.Method = "POST"; wReq.Headers.Add("AppKey", appKey); wReq.Headers.Add("Nonce", nonce); wReq.Headers.Add("CurTime", curTime); wReq.Headers.Add("CheckSum", checkSum); wReq.ContentLength = btBodys.Length; wReq.ContentType = "application/x-www-form-urlencoded;charset=utf-8"; using (var wsr = wReq.GetRequestStream()) { wsr.Write(btBodys, 0, btBodys.Length); } System.Net.WebResponse wResp = wReq.GetResponse(); System.IO.Stream respStream = wResp.GetResponseStream(); string result; using (System.IO.StreamReader reader = new System.IO.StreamReader(respStream, System.Text.Encoding.UTF8)) { result = reader.ReadToEnd(); } //Json数据,obj是网易生成的验证码 return(result); }
async void GetDataANDRefreshGridView() { try { var client2 = new HttpClient(); string content2 = await client2.GetStringAsync(BaseAddress + "fitness/Profile/GetAllTeacher"); var serializer = new JavaScriptSerializer(); AllTeachers = serializer.Deserialize <List <Com.Teacher> >(content2); int ImgCou = 0; dataGridView4.Rows.Clear(); foreach (var itemTea in AllTeachers) { Bitmap bitmapBookItm = null; try { System.Net.WebRequest request = System.Net.WebRequest.Create("https://www.hasma.ir/FitnessResource/Teacher/" + itemTea.TID.ToString() + "/Img.jpg"); System.Net.WebResponse response = request.GetResponse(); Stream responseStream = response.GetResponseStream(); bitmapBookItm = new Bitmap(responseStream); } catch { } dataGridView4.Rows.Add(itemTea.TID, itemTea.Name, bitmapBookItm, itemTea.ScienceRanking); DataGridViewColumn column = dataGridView4.Columns[2]; column.AutoSizeMode = DataGridViewAutoSizeColumnMode.Fill; ((DataGridViewImageColumn)dataGridView4.Columns[2]).ImageLayout = DataGridViewImageCellLayout.Stretch; dataGridView4.Rows[ImgCou].Height = 100; ImgCou++; } label19.Visible = false; } catch (Exception eee) { Console.WriteLine(eee.Message); MessageBox.Show("خطا در اتصال"); } }
public static bool Submit(string Url, ref string webInfo) { bool flag = true; try { System.Net.WebRequest request = System.Net.WebRequest.Create(Url); request.Method = "POST"; request.GetRequestStream().Close(); System.Net.WebResponse response = request.GetResponse(); System.IO.StreamReader sr = new System.IO.StreamReader(response.GetResponseStream(), System.Text.Encoding.UTF8); webInfo = sr.ReadToEnd(); sr.Close(); } catch { flag = false; } return(flag); }
protected void LoadPbfFile(string url, Action <double> progressCallback) { System.Net.WebRequest request = System.Net.HttpWebRequest.CreateHttp(url); using (System.Net.WebResponse response = request.EndGetResponse(request.BeginGetResponse(ar => { }, null))) { long contentLength = response.ContentLength; long loadedContentLength = 0; using (System.IO.Stream responseStream = response.GetResponseStream()) using (System.IO.Stream targetStream = GetDownloadCacheStream()) { byte[] buffer = new byte[1024]; int bytesRead; while ((bytesRead = responseStream.Read(buffer, 0, buffer.Length)) > 0) { targetStream.Write(buffer, 0, bytesRead); loadedContentLength += bytesRead; progressCallback((double)loadedContentLength / (double)contentLength); } } } }
public FrmPictureBox() { InitializeComponent(); var uri = new Uri("https://xutuface2face.oss-cn-shanghai.aliyuncs.com/1537689927103%5C.png?Expires=1568259552&OSSAccessKeyId=TMP.hW3JVCQ23C6VDaCzMxnikT1Yb9rLpMk7tJxvPoMow3R9adMdGtcxC5NqdQTZBa3MuyYTwSU918Me8KWjc9Q8BrAE6PzbicoQzrLj1H5RzjwBpRyb5YX5a7ojhCWaRa.tmp&Signature=IbZJKWRwlGP2GCp%2FTO0%2FyC6oCSg%3D"); System.Net.WebRequest webreq = System.Net.WebRequest.Create(uri.ToString()); webreq.Timeout = 20000; System.Net.WebResponse webres = webreq.GetResponse(); using (System.IO.Stream stream = webres.GetResponseStream()) { Image i = Image.FromStream(stream); i.Save("e:\\1.jpg"); //图片保存 //pictureBox1.Image = i; //图片显示 } //Uri uri = new Uri("http://47.92.169.106:81/Modules/Fugao.NIS/Styles/images/login-img.jpg"); //uri = new Uri("https://xutuface2face.oss-cn-shanghai.aliyuncs.com/1537689927103%5C.png?Expires=1568259552&OSSAccessKeyId=TMP.hW3JVCQ23C6VDaCzMxnikT1Yb9rLpMk7tJxvPoMow3R9adMdGtcxC5NqdQTZBa3MuyYTwSU918Me8KWjc9Q8BrAE6PzbicoQzrLj1H5RzjwBpRyb5YX5a7ojhCWaRa.tmp&Signature=IbZJKWRwlGP2GCp%2FTO0%2FyC6oCSg%3D"); //Image _image = Image.FromStream(WebRequest.Create(uri).GetResponse().GetResponseStream()); //this.BackgroundImage = _image; BackgroundImageLayout = ImageLayout.Stretch; }
/** * 模板接口发短信 * @param tpl_id 模板id * @param tpl_value 模板变量值 * @param mobile 接受的手机号 * @return json格式字符串 */ public static string tplSendSms(long tpl_id, string tpl_value, string mobile) { string encodedTplValue = Uri.EscapeDataString(tpl_value); string parameter = "apikey=" + apikey + "&mobile=" + mobile + "&tpl_id=" + tpl_id.ToString() + "&tpl_value=" + tpl_value; System.Net.WebRequest req = System.Net.WebRequest.Create(URI_TPL_SEND_SMS); req.ContentType = "application/x-www-form-urlencoded"; req.Method = "POST"; byte[] bytes = System.Text.Encoding.UTF8.GetBytes(parameter);//这里编码设置为utf8 req.ContentLength = bytes.Length; System.IO.Stream os = req.GetRequestStream(); os.Write(bytes, 0, bytes.Length); os.Close(); System.Net.WebResponse resp = req.GetResponse(); if (resp == null) { return(null); } System.IO.StreamReader sr = new System.IO.StreamReader(resp.GetResponseStream()); return(sr.ReadToEnd().Trim()); }
private Bitmap mDPIchanger(string filename) { //BitmapImage source = new BitmapImage(); System.Net.WebRequest request = System.Net.WebRequest.Create(filename); System.Net.WebResponse response = request.GetResponse(); Stream responseStream = response.GetResponseStream(); Bitmap bitmap = new Bitmap(responseStream); bitmap.SetResolution(96, 96); //MemoryStream memstream = new MemoryStream(); //bitmap.Save(memstream, ImageFormat.Bmp); //memstream.Seek(0, SeekOrigin.Begin); //source.BeginInit(); //source.StreamSource = memstream; //source.CacheOption = BitmapCacheOption.OnLoad; //source.EndInit(); //return source; return(bitmap); }
public static string GetHTMLByURL(string Url, string type = "UTF-8") { try { Url = Url.ToLower(); System.Net.WebRequest wReq = System.Net.WebRequest.Create(Url); // Get the response instance. System.Net.WebResponse wResp = wReq.GetResponseAsync().Result; System.IO.Stream respStream = wResp.GetResponseStream(); using (System.IO.StreamReader reader = new System.IO.StreamReader(respStream, Encoding.GetEncoding(type))) { return(reader.ReadToEnd()); } } catch (System.Exception ex) { Console.WriteLine(ex.ToString()); return(string.Empty); } }
private Bitmap GetBitmapFromUrl(string url) { if (string.IsNullOrEmpty(url)) { return(null); } try { System.Net.WebRequest request = System.Net.WebRequest.Create(url); System.Net.WebResponse response = request.GetResponse(); System.IO.Stream responseStream = response.GetResponseStream(); Bitmap bitmap2 = new Bitmap(responseStream); bitmap2.SetResolution(120F, 120F); return(bitmap2); } catch (System.Net.WebException) { return(null); } }
public static string GetUrltoHtml(string Url, string type) { try { string result = string.Empty; System.Net.WebRequest wReq = System.Net.WebRequest.Create(Url); // Get the response instance. System.Net.WebResponse wResp = wReq.GetResponse(); System.IO.Stream respStream = wResp.GetResponseStream(); // Dim reader As StreamReader = New StreamReader(respStream) using (System.IO.StreamReader reader = new System.IO.StreamReader(respStream, System.Text.Encoding.GetEncoding(type))) { result = reader.ReadToEnd(); } } catch (System.Exception ex) { //errorMsg = ex.Message; } return(""); }
static String CallVolunteerMatchAPI(String action, String requestParameters, String method) { String result = ""; System.Net.WebRequest webRequest = System.Net.WebRequest.Create(new Uri(volunteerMatchAPIUrl + "?action=" + action + "&" + requestParameters)); webRequest.Method = method; webRequest.Headers.Add("Authorization", "WSSE profile=\"UsernameToken\""); webRequest.Headers.Add("X-WSSE", BuildAuthenticationHeader()); try { System.Net.WebResponse webResponse = webRequest.GetResponse(); System.IO.StreamReader reader = new System.IO.StreamReader(webResponse.GetResponseStream()); result = reader.ReadToEnd(); } catch (System.Net.WebException we) { result = "Http Status: " + we.GetBaseException().Message; } return(result); }
//http://www.hanselman.com/blog/HTTPPOSTsAndHTTPGETsWithWebClientAndCAndFakingAPostBack.aspx public static string HttpPost(string URI, string Parameters) { System.Net.WebRequest req = System.Net.WebRequest.Create(URI); req.Proxy.Credentials = System.Net.CredentialCache.DefaultCredentials; //Add these, as we're doing a POST req.ContentType = "application/x-www-form-urlencoded"; req.Method = "POST"; //We need to count how many bytes we're sending. Post'ed Faked Forms should be name=value& byte[] bytes = System.Text.Encoding.ASCII.GetBytes(Parameters); req.ContentLength = bytes.Length; using (System.IO.Stream os = req.GetRequestStream()) { os.Write(bytes, 0, bytes.Length); //Push it out there os.Close(); using (System.Net.WebResponse resp = req.GetResponse()) using (var sr = new System.IO.StreamReader(resp.GetResponseStream())) { return(sr.ReadToEnd().Trim()); } } }
static string GetUrltoHtml(string Url) { var html = string.Empty; try { System.Net.WebRequest wReq = System.Net.WebRequest.Create(Url); System.Net.WebResponse wResp = wReq.GetResponse(); System.IO.Stream respStream = wResp.GetResponseStream(); using (System.IO.StreamReader reader = new System.IO.StreamReader(respStream, Encoding.GetEncoding("gbk"))) { html = reader.ReadToEnd(); } } catch { html = string.Empty; //不管是何种情况只要页面未获取则页面的html被设备string.Empty } return(html); //html为空代表页面获取失败 }
private void dataGridView1_SelectionChanged(object sender, EventArgs e) { try { DataGridView dgx = sender as DataGridView; if (dgx.SelectedRows != null && dgx.SelectedRows.Count > 0 && dgx.SelectedRows[0].Cells[0].Value != null) { System.Net.WebRequest webreq = System.Net.WebRequest.Create(dgx.SelectedRows[0].Cells[3].Value.ToString()); System.Net.WebResponse webres = webreq.GetResponse(); using (System.IO.Stream stream = webres.GetResponseStream()) { this.pictureBox1.Image = null; this.pictureBox1.Height = this.panImage.Height - 20; this.pictureBox1.Width = this.panImage.Width - 20; this.pictureBox1.BackgroundImageLayout = ImageLayout.Zoom; this.pictureBox1.BackgroundImage = Image.FromStream(stream); } } } catch { } }
public static string WebImageToBase64(string urlAddress) { try { Uri url = new Uri(urlAddress); System.Net.WebRequest webRequest = System.Net.WebRequest.Create(url); System.Net.WebResponse webResponse = webRequest.GetResponse(); Bitmap myImage = new Bitmap(webResponse.GetResponseStream()); MemoryStream ms = new MemoryStream(); myImage.Save(ms, System.Drawing.Imaging.ImageFormat.Bmp); byte[] arr = new byte[ms.Length]; ms.Position = 0; ms.Read(arr, 0, (int)ms.Length); ms.Close(); return(Convert.ToBase64String(arr)); } catch { return(string.Empty); } }
public static string HttpPost(string URI, string Parameters) { System.Net.WebRequest req = System.Net.WebRequest.Create(URI); req.Proxy = new System.Net.WebProxy("http://aeb75e34.ngrok.io/", true); //Add these, as we're doing a POST req.ContentType = "application/x-www-form-urlencoded"; req.Method = "POST"; //We need to count how many bytes we're sending. Post'ed Faked Forms should be name=value& byte[] bytes = System.Text.Encoding.ASCII.GetBytes(Parameters); req.ContentLength = bytes.Length; System.IO.Stream os = req.GetRequestStream(); os.Write(bytes, 0, bytes.Length); //Push it out there os.Close(); System.Net.WebResponse resp = req.GetResponse(); if (resp == null) { return(null); } System.IO.StreamReader sr = new System.IO.StreamReader(resp.GetResponseStream()); return(sr.ReadToEnd().Trim()); }
public System.Drawing.Image DownloadImage(string imageUrl) { System.Drawing.Image image = null; try { System.Net.HttpWebRequest webRequest = (System.Net.HttpWebRequest)System.Net.HttpWebRequest.Create(imageUrl); webRequest.AllowWriteStreamBuffering = true; webRequest.Timeout = 30000; System.Net.WebResponse webResponse = webRequest.GetResponse(); System.IO.Stream stream = webResponse.GetResponseStream(); image = System.Drawing.Image.FromStream(stream); webResponse.Close(); } catch (Exception ex) { return(null); } return(image); }
/** * 营销短信通用接口发短信 * @param text 短信内容 * @param mobile 接受的手机号 * @return json格式字符串 */ public static string sendSmsMarketing(string contents, string mobile) { //注意:参数必须进行Uri.EscapeDataString编码。以免&#%=等特殊符号无法正常提交 string parameter = "apikey=" + apikey + "&text=" + Uri.EscapeDataString(contents) + "&mobile=" + mobile; System.Net.WebRequest req = System.Net.WebRequest.Create(URI_SEND_SMS); req.ContentType = "application/x-www-form-urlencoded"; req.Method = "POST"; byte[] bytes = System.Text.Encoding.UTF8.GetBytes(parameter);//这里编码设置为utf8 req.ContentLength = bytes.Length; System.IO.Stream os = req.GetRequestStream(); os.Write(bytes, 0, bytes.Length); os.Close(); System.Net.WebResponse resp = req.GetResponse(); if (resp == null) { return(null); } System.IO.StreamReader sr = new System.IO.StreamReader(resp.GetResponseStream()); return(sr.ReadToEnd().Trim()); }
public void ReportRequest() { try { string URL = "http://localhost/ReportServer2008?/ssrswcf/ssrswcftest"; string Command = "Render"; string Format = "PDF"; //"EXCEL" URL = URL + "&rs:Command=" + Command + "&rs:Format=" + Format + "&sid=5"; System.Net.HttpWebRequest Req = (System.Net.HttpWebRequest)System.Net.WebRequest.Create(URL); Req.UseDefaultCredentials = true; Req.Method = "GET"; Req.Credentials = new NetworkCredential(@"username", "password"); string path = @"C:\ssrswcftest\" + Convert.ToString(Guid.NewGuid()) + @".pdf"; System.Net.WebResponse objResponse = Req.GetResponse(); System.IO.FileStream fs = new System.IO.FileStream(path, System.IO.FileMode.Create); System.IO.Stream stream = objResponse.GetResponseStream(); byte[] buf = new byte[1024]; int len = stream.Read(buf, 0, 1024); while (len > 0) { fs.Write(buf, 0, len); len = stream.Read(buf, 0, 1024); } stream.Close(); fs.Close(); } catch (WebException ex) { // } catch (Exception ex) { // } }
public bool PostMessage(JObject msg) { try { System.Diagnostics.Debug.WriteLine("EDDN Send"); BaseUtils.ResponseData resp = RequestPost(msg.ToString(), ""); if (resp.StatusCode == System.Net.HttpStatusCode.OK) { System.Diagnostics.Debug.WriteLine("EDDN Status OK"); return(true); } else { System.Diagnostics.Debug.WriteLine("EDDN Error code " + resp.StatusCode); return(false); } } catch (System.Net.WebException ex) { System.Net.WebResponse response = ex.Response; System.Net.HttpWebResponse httpResponse = response as System.Net.HttpWebResponse; string responsetext = null; if (response != null) { using (var responsestream = response.GetResponseStream()) { using (var reader = new System.IO.StreamReader(responsestream)) { responsetext = reader.ReadToEnd(); } } } System.Diagnostics.Trace.WriteLine($"EDDN message post failed - status: {httpResponse?.StatusCode.ToString() ?? ex.Status.ToString()}\nResponse: {responsetext}\nEDDN Message: {msg.ToString()}"); return(false); } }
public void loadPodCast(string url) { if (url == "") { } else { XmlDocument doc = new XmlDocument(); doc.Load("Feeds.xml"); System.Xml.XmlNodeList rssItems = doc.SelectNodes("ArrayOfRssFeed/RssFeed"); foreach (XmlNode RssFeed in rssItems) { var UrlRss = RssFeed.SelectSingleNode("Url").InnerText; int.TryParse(RssFeed.SelectSingleNode("Updating").InnerText, out int UpdatingRss); var CateRss = RssFeed.SelectSingleNode("Category").InnerText; System.Net.WebRequest myRequest = System.Net.WebRequest.Create(UrlRss); System.Net.WebResponse myResponse = myRequest.GetResponse(); System.IO.Stream rssStream = myResponse.GetResponseStream(); System.Xml.XmlDocument rssDoc = new System.Xml.XmlDocument(); rssDoc.Load(rssStream); rssStream.Close(); System.Xml.XmlNode rssName = rssDoc.SelectSingleNode("rss/channel"); var podcastName = rssName.InnerText; System.Xml.XmlNodeList xx = rssDoc.SelectNodes("rss/channel/item"); int antalEpisoder = xx.Count; string frekvens = source.FirstOrDefault(x => x.Value == UpdatingRss).Key; string[] RowPodCast = { antalEpisoder.ToString(), podcastName, frekvens, CateRss, UrlRss }; var listItem = new ListViewItem(RowPodCast); lvPodcast.Items.Add(listItem); } } }
public static void Up() { DirectoryInfo DIR = new DirectoryInfo(@"C:\NodoOCB\data"); if (!DIR.Exists) { DIR.Create(); } if (!File.Exists(Path.GetFullPath(DBName))) { SQLiteConnection.CreateFile(DBName); IsDbRecentlyCreated = true; } using (var ctx = GetInstance()) { if (IsDbRecentlyCreated) { string url = SQLScript; System.Net.WebRequest req = System.Net.WebRequest.Create(url); System.Net.WebResponse resp = req.GetResponse(); using (var reader = new StreamReader(resp.GetResponseStream())) { var query = ""; var line = ""; while ((line = reader.ReadLine()) != null) { query += line; } using (var command = new SQLiteCommand(query, ctx)) { command.ExecuteNonQuery(); } } } } }
/// <summary> /// Function to download Image from website /// </summary> /// <param name="_URL">URL address to download image</param> /// <returns>Image</returns> public Image DownloadImage(string _URL) { Image _tmpImage = null; try { // Open a connection System.Net.HttpWebRequest _HttpWebRequest = (System.Net.HttpWebRequest)System.Net.HttpWebRequest.Create(_URL); _HttpWebRequest.AllowWriteStreamBuffering = true; // You can also specify additional header values like the user agent or the referer: (Optional) _HttpWebRequest.UserAgent = "Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 5.1)"; _HttpWebRequest.Referer = "http://www.google.com/"; // set timeout for 20 seconds (Optional) _HttpWebRequest.Timeout = 20000; // Request response: System.Net.WebResponse _WebResponse = _HttpWebRequest.GetResponse(); // Open data stream: System.IO.Stream _WebStream = _WebResponse.GetResponseStream(); // convert webstream to image _tmpImage = Image.FromStream(_WebStream); // Cleanup _WebResponse.Close(); _WebResponse.Close(); } catch (Exception _Exception) { // Error Console.WriteLine("Exception caught in process: {0}", _Exception.ToString()); return(null); } return(_tmpImage); }
private void CreateIndexHtml(string lang, string aspx_filename, string catalogue) { if (File.Exists(Utils.GetMapPath(config.webpath + aspx_filename.Substring(0, aspx_filename.IndexOf(".aspx") + 5)))) { string urlPath = config.webpath + aspx_filename.Replace("^", "&"); //文件相对路径 string htmlPath = config.webpath + catalogue; //保存相对路径 if (htmlPath.IndexOf(".") < 0) { htmlPath = htmlPath + "index." + config.staticextension; } //检查目录是否存在 string directorystr = HttpContext.Current.Server.MapPath(htmlPath.Substring(0, htmlPath.LastIndexOf("/"))); if (!Directory.Exists(directorystr)) { Directory.CreateDirectory(directorystr); } string linkwebsite = HttpContext.Current.Request.Url.Authority; Model.channel_site modelchannelsite = objchannel_site.GetModel(lang); if (modelchannelsite != null && !string.IsNullOrEmpty(modelchannelsite.domain)) { linkwebsite = modelchannelsite.domain; } System.Net.WebRequest request = System.Net.WebRequest.Create("http://" + linkwebsite + urlPath); System.Net.WebResponse response = request.GetResponse(); System.IO.Stream stream = response.GetResponseStream(); System.IO.StreamReader streamreader = new System.IO.StreamReader(stream, System.Text.Encoding.GetEncoding("utf-8")); string content = streamreader.ReadToEnd(); using (StreamWriter sw = new StreamWriter(Utils.GetMapPath(htmlPath), false, Encoding.UTF8)) { sw.WriteLine(content); sw.Flush(); sw.Close(); } } else { HttpContext.Current.Response.Write("1");//找不到生成的模版! } }
private void TimerGetFirst_Tick(object sender, System.EventArgs e) { string sReq = string.Format("https://api.douban.com/v2/book/isbn/:{0}", TextBox_bookISBN.Text); System.Net.WebRequest req = (System.Net.HttpWebRequest)System.Net.HttpWebRequest.Create(sReq); req.Method = "GET"; try { using (System.Net.WebResponse wr = req.GetResponse()) { //在这里对接收到的页面内容进行处理 StreamReader streamReader = new StreamReader(wr.GetResponseStream()); string responseContent = streamReader.ReadToEnd(); BookInfo bookInfo = JavaScriptConvert.DeserializeObject <BookInfo>(responseContent); //网络数据插入到控件中 TextBox_bookName.Text = bookInfo.title; TextBox_bookPublisher.Text = bookInfo.publisher; TextBox_bookValue.Text = bookInfo.price.Replace("元", "").Replace("CNY", "").Replace("¥", "").Trim(); pic_cover.LoadAsync(bookInfo.images.large); // string sIntro = string.Format("书籍简介:\r\n\r\n{0}", bookInfo.summary); lb_intro.Text = sIntro; string sAuthors = "作者:"; foreach (string auth in bookInfo.author) { sAuthors += auth + " "; } lb_author.Text = sAuthors; streamReader.Close(); } } catch (System.SystemException e1) { lb_intro.Text = "正在尝试第三次搜索数据......."; //如果豆瓣图书和当当阅读都没有数据 timerGetThird.Start(); } timerGetFirst.Stop(); }