我提出了第三方Web服務的請求,並基於VB.net程序(.net 3.5)編寫了我的C#代碼(.net 4.0)。我幾乎完全複製命令,但無論我作爲域添加到我的cookie中,它都不起作用,並且在將cookie添加到容器時總是給我提供錯誤。Cookie域無效C#
該Cookie的'Domain'='https://secure.uat.globallink.com/gtss/service/FileWebService'部分無效。
VB.net程序可以正常使用此代碼並在生產環境中正常工作。我不知道爲什麼會發生這種情況。 .add方法在3.5和4.0之間是一樣的,我試過這個在互聯網上漂浮的BugFix_CookieDomain代碼,沒有任何幫助(我只有這個cookie)。我也嘗試添加一個沒有運氣的URI字段,並將域名更改爲「https://secure.uat.globallink.com」,但沒有任何工作。請幫助,我覺得我在這裏有點瘋狂。謝謝!
C#
GTSSWebService.FxWebService wsDL = new GTSSWebService.FxWebService();
wsDL.Credentials = new NetworkCredential(connectionCreds, Settings.mySettings.GTSSPassword);
wsDL.CookieContainer = new CookieContainer();
wsDL.Url = "https://secure.uat.globallink.com/gtss/service/FxWebService";
Cookie gtssConnCookie = new Cookie("SMCHALLENGE", "YES");
gtssConnCookie.Domain = "https://secure.uat.globallink.com/gtss/service/FileWebService";
wsDL.CookieContainer.Add(gtssConnCookie);
VB
Dim wsDL As New GTSSWebService.FxWebService
wsDL.Credentials = New System.Net.NetworkCredential(sCreds, Settings.DefaultSettings.PW)
wsDL.CookieContainer = New System.Net.CookieContainer
If Settings.DefaultSettings.ConnectLTS Then
wsDL.Url = "http://" & Settings.DefaultSettings.LTSIP & "/gtss/service/FxWebService"
Else
wsDL.Url = Settings.DefaultSettings.GTSSURL.Replace("/FileWebService", "/FxWebService")
Dim GTSSConnectionCookie As New Cookie("SMCHALLENGE", "YES")
GTSSConnectionCookie.Domain = Settings.DefaultSettings.GTSSURL
wsDL.CookieContainer.Add(GTSSConnectionCookie)
注 - Settings.DefaultSettings.GTSSURL == 「https://secure.uat.globallink.com/gtss/service/FileWebService」