zoukankan      html  css  js  c++  java
  • 如何在C# WinForm 程序中使用WebBrowser控件时设置COOKIE的值。

    .NET 中提供的WebBrowser 控件中的COOKIE无法直接设置,无奈之下只好使用API去设置COOKIE的值了。希望MS可以尽快提供在WebBrowser控件中任意设置Cookie的值。可惜的是在VS2010中也不能直接设置这个值。

    代码
    using System;
    using System.Runtime.InteropServices;

    public class CookieHelper
    {
      
    private string url;
      [DllImport(
    "wininet.dll", CharSet = CharSet.Auto, SetLastError = true)]

      
    public static extern bool InternetSetCookie(string lpszUrlName, string lbszCookieName, string lpszCookieData);

      
    public static void SetCookie(string path,string cookieName,string cookieValue)
      {
        
    this.url = path;

        
    // 设置Cookie的值
        InternetSetCookie(url, cookieName, cookieValue);
      }
    }

     

    代码
    // 清除所有COOKIE
    using System;
    using System.IO; 

    void clearIECache()
    {
      ClearFolder (
    new DirectoryInfo (Environment.GetFolderPath(Environment.SpecialFolder.InternetCache)));
    }
     
    void ClearFolder (DirectoryInfo folder)
    {
      
    foreach (FileInfo file in folder.GetFiles())
      {
        file.Delete(); 
      }

      
    foreach (DirectoryInfo subfolder in folder.GetDirectories())
      {
        ClearFolder(subfolder); 
      }
    }

      

  • 相关阅读:
    hard example mining(困难样本挖掘)
    Docker
    cmake使用教程
    CFENet: An Accurate and Efficient Single-Shot Object Detector for Autonomous Driving
    Week1
    To-Read List
    《人性的弱点》读书笔记及读后感
    总结计划:2018:上半年——毕业前
    TCP网路程序设计
    Linux 串口驱动设计二
  • 原文地址:https://www.cnblogs.com/leeairw/p/1744602.html
Copyright © 2011-2022 走看看