【发布时间】:2023-03-16 05:25:01
【问题描述】:
【问题讨论】:
-
看在上帝的份上,@Jacob。每次你没有得到你想要的答案时,你不会问一个新问题,你编辑你的问题并让它变得更好。你已经问过这个特定问题的变体至少 5 次了。
标签: c# proxy internetsetoption
【问题讨论】:
标签: c# proxy internetsetoption
public 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)
{
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));
// Converting structure to IntPtr
Marshal.StructureToPtr(struct_IPI, intptrStruct, true);
bool iReturn = InternetSetOption(IntPtr.Zero, INTERNET_OPTION_PROXY, intptrStruct, Marshal.SizeOf(struct_IPI));
}
private void Usage()
{
RefreshIESettings("1.2.3.4:8080");
object nullObject = 0;
string strTemp = "";
object nullObjStr = strTemp;
axWebBrowser1.Navigate("http://test.com", ref nullObject, ref nullObjStr, ref nullObjStr, ref nullObjStr);
}
【讨论】:
DllImport 添加'使用 System.Runtime.InteropServices'