-
大小: 9.85MB文件类型: .zip金币: 1下载: 0 次发布日期: 2023-11-05
- 语言: 其他
- 标签: webbrowser
资源简介
解决了webbrowser下载文件的三个问题:
1、屏蔽了另存为的弹出
2、获得webbrowser所有的cookie值
3、让webclient支持cookie
代码片段和文件信息
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.IO;
using System.Timers;
using mshtml;
using System.Net;
using System.Runtime.InteropServices;
using System.Security;
using System.Security.Permissions;
namespace WindowsFormsApplication1
{
public partial class Form1 : Form
{
public string downxlsfile = ““;
public string visifile = “http://www.baidu.com“;
public String newfilename = ““;
public Form1()
{
InitializeComponent();
webBrowserMMB.Navigate(visifile);
webBrowserMMB.Navigating += new WebBrowserNavigatingEventHandler(webBrowser1_Navigating);
}
public String getWebBrowserHtml(string listurl)
{
comboBoxUrl.Text = listurl;
webBrowserMMB.scriptErrorsSuppressed = true;
webBrowserMMB.Navigate(listurl);
txtState.Text = “开始加载“;
return ““;
}
void client_DownloadFileCompleted(object sender AsyncCompletedEventArgs e)
{
//MessageBox.Show(“File downloaded“);
//下载完成以后,要去处理的事
txtState.Text = newfilename;
}
private void webBrowser1_Navigating(object sender WebBrowserNavigatingEventArgs e)
{
String seg = e.Url.Segments[e.Url.Segments.Length - 1];
if (seg.EndsWith(“getTbkPaymentDetails.json“))//.xls
{
e.Cancel = true;
newfilename=DateTime.Now.ToString().Replace(“:“ ““).Replace(“ “ ““).Replace(“-“ ““).Replace(“/“ ““) + “.xls“;
string filepath = “D:/down/“ + newfilename;
CookieContainer cookieContainer = new CookieContainer();
//string cookieStr = webBrowserMMB.Document.Cookie;
String cookieStr = FullWebBrowserCookie.GetCookieInternal(new Uri(visifile) true);
string[] cookstr = cookieStr.Split(‘;‘);
bool islogined = false;
foreach (string str in cookstr)
{
string[] cookieNameValue = str.Split(‘=‘);
if (cookieNameValue[0].Trim() == “userss“)
{
islogined = true;
}
Cookie ck = new Cookie(cookieNameValue[0].Trim().ToString() cookieNameValue[1].Trim().ToString());
ck.Domain = ““;//必须写对
cookieContainer.Add(ck);
}
if (islogined == true)
{
HttpClient hc = new HttpClient(cookieContainer);
hc.DownloadFileCompleted += new AsyncCompletedEventHandler(client_DownloadFileCompleted);
hc.DownloadFileAsync(e.Url filepat
属性 大小 日期 时间 名称
----------- --------- ---------- ----- ----
目录 0 2014-04-10 08:19 WebBrowserDown\
目录 0 2014-04-10 08:19 WebBrowserDown\WebBrowserGetHtmlByCookie\
文件 897 2014-04-09 23:37 WebBrowserDown\WebBrowserGetHtmlByCookie.sln
文件 29696 2014-04-10 08:25 WebBrowserDown\WebBrowserGetHtmlByCookie.suo
目录 0 2014-04-10 08:19 WebBrowserDown\WebBrowserGetHtmlByCookie\bin\
目录 0 2014-04-10 08:19 WebBrowserDown\WebBrowserGetHtmlByCookie\bin\Debug\
文件 23133696 2014-03-01 14:05 WebBrowserDown\WebBrowserGetHtmlByCookie\bin\Debug\mshtml.dll
文件 6763 2014-04-09 20:33 WebBrowserDown\WebBrowserGetHtmlByCookie\bin\Debug\myaa
文件 16384 2014-04-09 23:34 WebBrowserDown\WebBrowserGetHtmlByCookie\bin\Debug\WindowsFormsApplication1.exe
文件 34304 2014-04-09 23:34 WebBrowserDown\WebBrowserGetHtmlByCookie\bin\Debug\WindowsFormsApplication1.pdb
文件 11608 2014-04-10 08:19 WebBrowserDown\WebBrowserGetHtmlByCookie\bin\Debug\WindowsFormsApplication1.vshost.exe
文件 490 2013-06-18 20:28 WebBrowserDown\WebBrowserGetHtmlByCookie\bin\Debug\WindowsFormsApplication1.vshost.exe.manifest
目录 0 2014-04-09 17:37 WebBrowserDown\WebBrowserGetHtmlByCookie\bin\Release\
文件 7928 2014-04-10 08:21 WebBrowserDown\WebBrowserGetHtmlByCookie\Form1.cs
文件 5232 2014-04-09 21:56 WebBrowserDown\WebBrowserGetHtmlByCookie\Form1.Designer.cs
文件 6215 2014-04-09 21:56 WebBrowserDown\WebBrowserGetHtmlByCookie\Form1.resx
文件 4064 2014-04-09 20:54 WebBrowserDown\WebBrowserGetHtmlByCookie\GetHtmlByCookie.csproj
文件 5587 2014-04-09 20:48 WebBrowserDown\WebBrowserGetHtmlByCookie\HttpClient.cs
目录 0 2014-04-10 08:19 WebBrowserDown\WebBrowserGetHtmlByCookie\obj\
目录 0 2014-04-10 08:19 WebBrowserDown\WebBrowserGetHtmlByCookie\obj\x86\
目录 0 2014-04-10 08:19 WebBrowserDown\WebBrowserGetHtmlByCookie\obj\x86\Debug\
文件 1229 2014-04-09 19:24 WebBrowserDown\WebBrowserGetHtmlByCookie\obj\x86\Debug\DesignTimeResolveAssemblyReferences.cache
文件 6233 2014-04-10 08:19 WebBrowserDown\WebBrowserGetHtmlByCookie\obj\x86\Debug\DesignTimeResolveAssemblyReferencesInput.cache
文件 1850 2014-04-10 08:19 WebBrowserDown\WebBrowserGetHtmlByCookie\obj\x86\Debug\GetHtmlByCookie.csproj.FileListAbsolute.txt
文件 975 2014-04-09 23:34 WebBrowserDown\WebBrowserGetHtmlByCookie\obj\x86\Debug\GetHtmlByCookie.csproj.GenerateResource.Cache
文件 700 2014-04-09 23:34 WebBrowserDown\WebBrowserGetHtmlByCookie\obj\x86\Debug\GetHtmlByCookie.csproj.ResolveComReference.cache
目录 0 2014-04-09 16:10 WebBrowserDown\WebBrowserGetHtmlByCookie\obj\x86\Debug\TempPE\
文件 1246 2014-04-09 23:34 WebBrowserDown\WebBrowserGetHtmlByCookie\obj\x86\Debug\WindowsFormsApplication1.csproj.FileListAbsolute.txt
文件 975 2014-04-09 23:34 WebBrowserDown\WebBrowserGetHtmlByCookie\obj\x86\Debug\WindowsFormsApplication1.csproj.GenerateResource.Cache
文件 700 2014-04-09 23:34 WebBrowserDown\WebBrowserGetHtmlByCookie\obj\x86\Debug\WindowsFormsApplication1.csproj.ResolveComReference.cache
文件 16384 2014-04-09 23:34 WebBrowserDown\WebBrowserGetHtmlByCookie\obj\x86\Debug\WindowsFormsApplication1.exe
............此处省略10个文件信息
- 上一篇:ADAMS_car完整教程
- 下一篇:LDPC低密度奇偶校验码
相关资源
-
em
beddedWB (em bedded Web Browser) 17 -
em
beddedWebBrowser D5-XE2 - 使用webBrowser采集网页数据
- CefSharp调用google浏览器内核ChromiumWeb
- CefSharp Browser Chromium内核 WebBrowser 控件
-
vc2010使用minibl
ink控件开发浏览器简 -
基于minibl
ink封装的WebBrowser控件CXM - webBrowser 禁用消息框alert 并且获得内
- VS环境WebBrowser开发的简单分页浏览器
- WebBrowser网页操作(提取元素自动填表
- webbrowser新版中文版1.0.npk
-
em
beddedWB_D5-XE2_Version_14.70.0 - Webbrowser调用dll简单方便获取request r
- DELPHI+chrome+替换WebBrowser让你的程序嵌
评论
共有 条评论