Bonjour,

j'utilise le code (fonction RefreshIESettings) ci dessous pour changer le proxy du webbrowser. Cette partie fonctionne très bien.

Par contre la partie où j'indique le pseudo et mot de passe de connexion au proxy retourne tjs faux.

quelqu'un a t il déjà eu ce problème ?

Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
 
 struct Struct_INTERNET_PROXY_INFO
{
    public int dwAccessType;
    public IntPtr proxy;
    public IntPtr proxyBypass;
};
 
 
 
[DllImport("wininet.dll", SetLastError = true)]
private static extern bool InternetSetOption(IntPtr hInternet, int dwOption, IntPtr lpBuffer, int lpdwBufferLength);
 
private void RefreshIESettings(string strProxy, string username, string password)
{
    const int INTERNET_OPTION_PROXY = 38;
    const int INTERNET_OPEN_TYPE_PROXY = 3;
    const int INTERNET_OPTION_PROXY_USERNAME = 43;
    const int INTERNET_OPTION_PROXY_PASSWORD = 44;
    IntPtr pseudo;
    IntPtr mdp;
 
    pseudo = Marshal.StringToHGlobalAnsi(username);
     mdp=Marshal.StringToHGlobalAnsi(password);
    Struct_INTERNET_PROXY_INFO struct_IPI;
 
    // Filling in structure
    struct_IPI.dwAccessType = INTERNET_OPEN_TYPE_PROXY;
    struct_IPI.proxy = Marshal.StringToHGlobalAnsi(strProxy);
    struct_IPI.proxyBypass = Marshal.StringToHGlobalAnsi("local");
 
    // Allocating memory
    IntPtr intptrStruct = Marshal.AllocCoTaskMem(Marshal.SizeOf(struct_IPI));
 
    // Converting structure to IntPtr
    Marshal.StructureToPtr(struct_IPI, intptrStruct, true);
 
    bool iReturn = InternetSetOption(IntPtr.Zero, INTERNET_OPTION_PROXY, intptrStruct, Marshal.SizeOf(struct_IPI));
    Marshal.GetNativeVariantForObject(username, pseudo);
    Marshal.GetNativeVariantForObject(password, mdp);
    bool resultF = InternetSetOption(IntPtr.Zero, INTERNET_OPTION_PROXY_USERNAME, pseudo, username.Length + 1);
    var errorF = Marshal.GetLastWin32Error();
 
    //-- Set Proxy Password
    bool resultG = InternetSetOption(IntPtr.Zero, INTERNET_OPTION_PROXY_PASSWORD, mdp, password.Length + 1);
    var errorG = Marshal.GetLastWin32Error();
 
 
 
 
}
La variable errorG est tjs à faux.

Merci de vos conseils