@@ -38,8 +38,8 @@ type Ehttp struct {
38
38
E代理方式 int
39
39
//代理ip
40
40
Proxy string
41
- ProxyUser string
42
- ProxyPass string
41
+ //代理用户名:代理密码
42
+ ProxyAuth string
43
43
//全局头信息
44
44
全局头信息 string
45
45
//默认头信息
@@ -447,9 +447,8 @@ func (this *Ehttp) setObj() *Ehttp {
447
447
trans .Proxy = func (_ * http.Request ) (* url.URL , error ) {
448
448
return url .Parse (this .Proxy )
449
449
}
450
- if len (this .ProxyUser )> 0 && len (this .ProxyPass )> 0 {
451
- auth := this .ProxyUser + ":" + this .ProxyPass
452
- encodedAuth := base64 .StdEncoding .EncodeToString ([]byte (auth ))
450
+ if len (this .ProxyAuth ) > 3 && strings .Index (this .ProxyAuth , ":" ) > - 1 {
451
+ encodedAuth := base64 .StdEncoding .EncodeToString ([]byte (this .ProxyAuth ))
453
452
454
453
trans .ProxyConnectHeader = http.Header {
455
454
"Proxy-Authorization" : []string {"Basic " + encodedAuth },
@@ -474,23 +473,22 @@ func (this *Ehttp) setObj() *Ehttp {
474
473
return this
475
474
}
476
475
477
- // SetProxy 设置代理访问, 如果没有 用户名 密码,则留""
476
+ // SetProxy 设置代理访问, 如果没有 用户名 密码,则留"",带用户名和密码的用法:SetProxy("127.0.0.1:8888","user:pass") 不带的用法:SetProxy("127.0.0.1:8888","")
478
477
//
479
478
// SetProxy("http://127.0.0.1:8888")
480
- func (this * Ehttp ) SetProxy (proxy string ,proxyUser string , proxyPass string ) * Ehttp {
479
+ func (this * Ehttp ) SetProxy (proxy string ,proxyAuth string ) * Ehttp {
481
480
//检查 前面是否带有 http:// 或者 https:// 如果没有则自动添加 socks5:// 则不自动添加
482
481
if strings .Index (proxy , "://" ) == - 1 {
483
482
proxy = "http://" + proxy
484
483
}
485
484
486
485
this .Proxy = proxy
487
- this .ProxyUser = proxyUser
488
- this .ProxyPass = proxyPass
486
+ this .ProxyAuth = proxyAuth
489
487
490
488
return this
491
489
}
492
- func (this * Ehttp ) E设置全局HTTP代理 (proxy string ,proxyUser string , proxyPass string ) * Ehttp {
493
- return this .SetProxy (proxy ,proxyUser , proxyPass )
490
+ func (this * Ehttp ) E设置全局HTTP代理 (proxy string ,proxyAuth string ) * Ehttp {
491
+ return this .SetProxy (proxy ,proxyAuth )
494
492
}
495
493
func (this * Ehttp ) SetTimeOut (超时时间 int ) * Ehttp {
496
494
this .TimeOut = 超时时间
0 commit comments