본문으로 바로가기

Webbrowser 에서 Proxy 설정하기

category Coding/C# 2015. 11. 13. 23:41
반응형

using System.Runtime.InteropServices; // dll import할때 필요



public struct Struct_INTERNET_PROXY_INFO

{

    public int dwAccessType;

    public IntPtr proxy; // IP and port

    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)

{

const int INTERNET_OPTION_PROXY = 38;

const int INTERNET_OPEN_TYPE_PROXY = 3;


Struct_INTERNET_PROXY_INFO struct_IPI;


struct_IPI.dwAccessType = INTERNET_OPEN_TYPE_PROXY;

struct_IPI.proxy = Marshal.StringToHGlobalAnsi(strProxy);

struct_IPI.proxyBypass = Marshal.StringToHGlobalAnsi("local");


IntPtr intptrStruct = Marshal.AllocCoTaskMem(Marshal.SizeOf(struct_IPI));


Marshal.StructureToPtr(struct_IPI, intptrStruct, true);


bool iReturn = InternetSetOption(IntPtr.Zero, INTERNET_OPTION_PROXY, intptrStruct, Marshal.SizeOf(struct_IPI));

}


RefreshIESettings ("프록시ip:port");

webBrowser1.Navigate ("http://naver.com");

반응형

'Coding > C#' 카테고리의 다른 글

C# 디시인사이드 유동닉 댓글달기  (2) 2015.11.18
Regex 그룹명 붙이기  (0) 2015.11.17
WinhttpRequest  (0) 2015.11.13
Regex 활용하여 파싱하기  (0) 2015.11.12
디시인사이드 새글알리미  (7) 2015.11.11