C#HTTP????????????????
???????????? ???????[ 2013/8/1 14:08:21 ] ????????
????HTTP??????????????????????????????????????????????????????SOCKET????????HTTP??????????????????????????
???????????????????????????????????????
??????????????????????
??????????????IP?????
???????????????????
????????????????????????Ч????????????????????????????????????API??????????Ч??
????????????????
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Runtime.InteropServices;
using System.Diagnostics;
using Microsoft.Win32;
namespace UtilSp.ClassLib
{
public class ProxySp
{
[DllImport("wininet.dll"?? SetLastError = true)]
private static extern bool InternetSetOption(IntPtr hInternet?? int dwOption?? IntPtr lpBuffer?? int lpdwBufferLength);
private const int INTERNET_OPTION_REFRESH = 37;
private const int INTERNET_OPTION_PROXY = 38;
private const int INTERNET_OPTION_SETTINGS_CHANGED = 39;
private const int INTERNET_OPEN_TYPE_PROXY = 3;
private const int INTERNET_OPEN_TYPE_DIRECT = 1;
#region changeUserAgent Function
public static void changeUserAgent()
{
var appName = Process.GetCurrentProcess().MainModule.ModuleName;
RegeditSp.write(@"HKEY_LOCAL_MACHINESOFTWAREMicrosoftInternet ExplorerMAINFeatureControlFEATURE_BROWSER_EMULATION"?? appName?? 9999?? RegistryValueKind.DWord);
}
#endregion
#region setProxyEnabled Function
/// <summary>
/// Set proxy.
/// </summary>
/// <param name="isProxyEnabled">true:is enabled.false:is not enabled.</param>
/// <param name="proxyIP">Proxy ip and port.Format:192.168.100.162:8080</param>
/// <returns></returns>
public static bool setProxy(bool isProxyEnabled?? string proxyIP = "")
{
string regPath = "Software\Microsoft\Windows\CurrentVersion\Internet Settings";//Enabled proxy option.
bool isSetProxyEnabledOk =
RegeditSp.write(RegeditSp.REGEDIT_ROOT_SET.HKEY_CURRENT_USER??
regPath??
"ProxyEnable"??
isProxyEnabled ? 1 : 0??
true);
bool isSetProxyIP = true;
if (!string.IsNullOrEmpty(proxyIP))
{
isSetProxyIP = RegeditSp.write(RegeditSp.REGEDIT_ROOT_SET.HKEY_CURRENT_USER??
regPath??
"ProxyServer"??
proxyIP??
true);
}
bool isConnectionOK=setConnection(isProxyEnabled?? proxyIP);
bool isNotifyOk = InternetSetOption(IntPtr.Zero?? INTERNET_OPTION_SETTINGS_CHANGED?? IntPtr.Zero?? 0);//Notify proxy in the regedit has changed.Lanuch proxy when connect next.
bool isReadOK = InternetSetOption(IntPtr.Zero?? INTERNET_OPTION_REFRESH?? IntPtr.Zero?? 0);//Read proxy from regedit.
return isSetProxyEnabledOk && isSetProxyIP && isNotifyOk && isReadOK && isConnectionOK;
}
#endregion
#region setConnection Function
private static bool setConnection(bool isProxyEnabled?? string proxyIP)
{
string regPath = "Software\Microsoft\Windows\CurrentVersion\Internet Settings\Connections";//Connection register option.
byte[] szBuf = new byte[80];
szBuf[0] = 0x3c;
szBuf[4] = 0x09;
szBuf[8] = (byte)(isProxyEnabled ? 0x03 : 0x01);
szBuf[12] = (byte)proxyIP.Length;
for (int i = 0; i < proxyIP.Length; i++)
{
szBuf[i + 16] =(byte)Convert.ToInt32(proxyIP[i]);
}
string local = "<local>";
for (int j = 0; j < 7; j++)
{
szBuf[20 + proxyIP.Length + j] = (byte)Convert.ToInt32(local[j]);
}
return RegeditSp.write(RegeditSp.REGEDIT_ROOT_SET.HKEY_CURRENT_USER??
regPath??
"???????"??
szBuf??
true);
}
#endregion
}
}
??????????????http://download.csdn.net/detail/xxdddail/5831359?????????????????????IP?б???????????
??????
???·???
??????????????????
2023/3/23 14:23:39???д?ò??????????
2023/3/22 16:17:39????????????????????Щ??
2022/6/14 16:14:27??????????????????????????
2021/10/18 15:37:44???????????????
2021/9/17 15:19:29???·???????·
2021/9/14 15:42:25?????????????
2021/5/28 17:25:47??????APP??????????
2021/5/8 17:01:11