zoukankan      html  css  js  c++  java
  • 对本程序使用自己的代理服务器

    int __fastcall XSetProxy(void)
    {
         // TODO: 设置代理服务器。
         //返回错误代码:
         //0:不使用代理      -1:
         TIniFile *ReadIni = new TIniFile(GetAppPath()+AnsiString(G_CONFIG_INI));
         bool bUseProxy                  = ReadIni->ReadBool("FormSet","UseProxy",false);
         AnsiString ProxySvr      = ReadIni->ReadString("FormSet","ProxySvr","");
         AnsiString ProxyPort      = ReadIni->ReadInteger("FormSet","ProxyPort",0);
         AnsiString UserName      = ReadIni->ReadString("FormSet","ProxyUser","");
         AnsiString UserPassWord = ReadIni->ReadString("FormSet","ProxyPsw","");
         delete ReadIni;
         ReadIni = NULL;
    
         AnsiString strProxy,temp;
    
    
         if(ProxySvr.Pos("http://")>0)
        {
            ProxySvr = ProxySvr.SubString(8,ProxySvr.Length());
        }
        else if(ProxySvr.Pos("https://")>0)
        {
            ProxySvr = ProxySvr.SubString(9,ProxySvr.Length());
        }
        temp.sprintf("%s:%s",ProxySvr,ProxyPort);
        strProxy.sprintf("http=http://%s;ftp=http://%s;https=https://%s",
                        temp,temp,temp);
    
         //get current setting
         INTERNET_PROXY_INFO ipi;
         DWORD dwSize2 = sizeof(ipi);
    
         //先设置成不使用代理。
         ipi.dwAccessType = INTERNET_OPEN_TYPE_DIRECT;
         InternetSetOption(NULL, INTERNET_OPTION_PROXY, &ipi, dwSize2);
         InternetSetOption(NULL, INTERNET_OPTION_REFRESH, NULL, NULL);
         InternetSetOption(NULL, INTERNET_OPTION_SETTINGS_CHANGED, NULL, 0);
         if(!bUseProxy) return ERROR_NOERROR;
    
         ipi.dwAccessType = INTERNET_OPEN_TYPE_PROXY ;
         ipi.lpszProxy = strProxy.c_str();
         ipi.lpszProxyBypass = "<local>";
         if(!InternetSetOption(NULL, INTERNET_OPTION_PROXY, &ipi, dwSize2))
         {
               //MessageBox(Application->Handle,"Set proxy fail.","SetProxyFail",MB_OK|MB_ICONERROR);
               return ERROR_SETPROXY;
         }
         //下面设置用户名和密码
         //WINAPI不支持Sock5。
    //      if(UserName!="" && UserPassWord!="")
    //      {
    //            char pProxyInfo[200]={0};
    //            lstrcpy(pProxyInfo,UserName.c_str());
    //            if(!InternetSetOption(NULL, INTERNET_OPTION_PROXY_USERNAME,
    //                                           (LPVOID)pProxyInfo ,lstrlen (pProxyInfo)))
    //            {
    //                  return ERROR_SETUSER;
    //            }
    //
    //            memset(pProxyInfo,0x00,200);
    //            lstrcpy(pProxyInfo,UserPassWord.c_str());
    //            if(!InternetSetOption(NULL, INTERNET_OPTION_PROXY_PASSWORD,
    //                                            (LPVOID)pProxyInfo ,lstrlen (pProxyInfo)))
    //            return ERROR_SETPSW;
    //      }
         return ERROR_NOERROR;
    }
  • 相关阅读:
    使用Git遇到的问题及解决方案(初级)
    巧记前端易混淆的英文语法
    编程助手JavaScript学习库-DOM笔记
    编程助手JavaScript学习库-面向对象编程笔记
    JS原始类型:数值的运用技巧
    这题目有毒之干不过codewars的OJ系统(一)
    Javascript运算符进阶指南
    Qt:During startup program exited with code 0xc0000135
    QT 消息处理机制
    Windows环境 和 Linux环境下搭建Qt开发环境
  • 原文地址:https://www.cnblogs.com/wlmbz/p/4919242.html
Copyright © 2011-2022 走看看