How to get the Correct Value for Cookie for HTTPSecureSocket

How can I get the correct “Value” of a URL’s Cookie previously loaded on HTMLViewer?

I dunno to call it “Value.” because I tried a different value that another people that catch this “value” of the cookie, that uses VB.net with C.
I tried with Christian’s MBS Plugins NSHTTPCookieMBS = NSHTTPCookieStorageMBS.sharedHTTPCookieStorage.cookiesForURL(“https://portalcfdi.facturaelectronica.sat.gob.mx/ConsultaReceptor.aspx”)

And I get different values from “CookieName” and “CookieValue”, and thats How the requested value must be look, in order to pass it to an HTTPSecureSocket

SITESERVER=ID= 7fd5bd16212ab8ee 74c3aeba 7bce4341;
FedAuthCONT = 77u/PD94bWwgdmVyc21vbj0iMS4wli81bmNvZG1uZz0idXRml T giPz48U2VjdlUpdHIDb250ZXhOVG9rZW4gcDE6SWQ91180YzA5YTlyOS1 kOTASL TRjNzktYjkzZSOxZmESM DQ2MTg2ZjctMzgyNTAyMTQxRjlzQUIOMDg3QkVCMEQzNDQ5RDd80TlilHhtbG5z0nAxPSJodHRwOi8vZG9jcy5vYXNpcy1vcGVulm9yZy93c3MvMjAwNC8wMS9vYXNpcy0yMDAOM DEtd3NzLXdzc2VjdlUpdHktdXRpbGIOeSOxljAueHNkli84bWxucz0iaHROcDovl2RvV3Mub2FzaXMtb381bi5vcmcvd3Mtc3gvd3Mtc2VjdlUIV29udmVyc2FOaW9ulzlwMDUxMil +PElkZW50a WZpZXI +dlUuOnV1 aWQ6NDUyYWl30TltZGVhMyOONjUyl WFkVzctZWY20DRhNzU2NzVmPC9JZGVudGlmaWVyPjxDb29raWUgeG1 sbnM91mhOdHA6L y9zY2hlbWFzlm 1 p V3Jvc29mdC 5jb20vd3MvMjAwNi8wNS9zZWN1 cmlOeSI + ZOF8QUFIY2NCMnRGT3ZoUER8UONZVOVCVIU2L 1 QxSnN3dDFsZIVSSHN3b05jaUJKUm52Z2w4bW5ralp YWj8wOEJ6SHY1 SUxHZE82L2YySH 8LZXhKTGEzMUJvM29ocVM2L 1A2VlUZTHlvcXgOUSs3c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ZXIJT3pVZkNMNG h 1 L2Fh T mk5d21 oVnRoRkcrZDVw TUR6WTRWEVNZnNpQU15MHZrZHFjdldPazJTRIR5QkdpekRNUIZwVXp4bGhkMWwOZldZZ1UwRjRCc3JnSUF5MVZ4dlV5VjNyM18xeXhSVzJjZEtvZHI 3b TZUVkwraOgwNDUvRTFwK2h8dnoxOWhla ThLMXZqc3V5Vm5W29xb TII;
FedAuthCONT1 =0mlrcXIMaUxpOUorajh6Smo4TE9ReU11 cU1yZORoazRwN3h4dk9RZ3JtbitWcGx1 enpWdVdoQXNsUk5RZTNrajc2ZnpuUVFqbS840W4zNE55T m 1 FZkx6NzVTbk 1 GQIFN RG9pWStuSlg 1 M3dWYWYvZUM4TOxlVkVwZW4rOVJpOGpiQ2xpeWM2VWZySWkOa T czN2FVY1 FPRzVSamVFTI c5UjNCbld4SHFoOGR2UWZQaERwZWpzOTRneVFn TFVhNV8tNWJMeU oxelJtTGt1 SlhybkROdnlT dUFSblR2T mxRRk8xcXRZNnVTZ1 kwMDNidn80UGgzZEFSS1 hsMWU3ZE1 ndnQrdz09PC9Db29raWU +PC9TZWN1 cm10eUNvbnRleHRUb2tlbj4=;
ASP .NET _ Sessionld=jmnblybuxntyicr4o2xrg2nd; _ CSRFCOOKIE=2dd24289-8de5-4364-baa0-beb851 bf43a 7

Impossible to say if you don’t control the server application. Just loop through them and append them all to your socket.

And Yes, As you Say, I check The VB.Net code of the other person that Download files from that website.

He use Webclient.Headers.Add(Httprquestheader.cookie, cookie)

Where:
Httprquestheader.cookie = “Cookie”
Cookie = THE BIIIIIIGG TEXT THAT I POSTED PREVIOUSLY THAT STARTS WITH SITESERVER=ID=BLABLABLA

So In Xojo I need to use as this way: HTTPSecureSocket.SetRequestHeader(“Cookie”,“StringwithCookieValue”)

The code has a loop. It makes an Array and for each cookie on MBSCookieStorage List a value in an array, but Im Gonna search more about it.

[quote=231886:@Gerardo García]

So In Xojo I need to use as this way: HTTPSecureSocket.SetRequestHeader(“Cookie”,“StringwithCookieValue”)[/quote]

Well technically it would be:

mySocket.SetRequestHeader(“Set-Cookie”, “” + StringwithCookieName + “” + “=” + StringwithCookieValue)

Cookies are HTTP headers called “Set-Cookie” not just “Cookie”. Also your string value does not need quotations around it. Also you should use your instance of HTTPSecureSocket (aka MySocket) not HTTPSecureSocket directly. Im sure you know just clarifying.

I probed the VB code in 3 different Windows machines and Obiously I know that get different values, but one thing always is the same:

At start of text these values:
SITESERVER=ID
FedAuthCONT
FedAuthCONT1

And At end of the text that values:
ASP.NET_SessionId=
CSRFCOOKIE=

Well according to Wikipedia “Cookie” and “Set-Cookie” are both valid headers.

[quote=231891:@Gerardo García]I probed the VB code in 3 different Windows machines and Obiously I know that get different values, but one thing always is the same:

At start of text these values:
SITESERVER=ID
FedAuthCONT
FedAuthCONT1

And At end of the text that values:
ASP.NET_SessionId=
CSRFCOOKIE=[/quote]

myHttpSocket.SetRequestHeader(“Set-Cookie”, “SITESERVER=ID; FedAuthCONT=?; FedAuthCONT1=?; ASP.NET_SessionId=?; CSRFCOOKIE=?”)

Of Course, I decided to explore the usage of the MBS Plugin for Cookies, and thats the code of what I’m using, in order to see what Cookie names and what Cookie values I have for this URL:

[b] Dim CookieValue, CookieName As String

// query list of all cookies in shared storage
dim cookies(-1) as NSHTTPCookieMBS = NSHTTPCookieStorageMBS.sharedHTTPCookieStorage.cookiesForURL(“https://portalcfdi.facturaelectronica.sat.gob.mx/ConsultaReceptor.aspx”)

// we collect values for SHCP:
dim list(-1), Valores(-1) as string
for each cookie as NSHTTPCookieMBS in cookies
List.Append “Nombre(”+ cookie.name
Valores.Append "Valor: " + cookie.value

next

// and display them
CookieName = join(list, EndOfLine)
CookieValue = join(Valores,EndOfLine)
galleta.Text = CookieName + EndOfLine + CookieValue[/b]

And I looking that I have all the values required but in different order, So I need to Assemble it in a correct order ignorer to get the final Sting exactly as the HeaderRequest requires in order to download the file.

So my question is:
In “FOR EACH” How can I tell to the code a Msgbox with the Number of times that a cookie is found.

I know how to do it on a For i As Integer = 0 to Ubound(Array)
Msgbox Cstr(i)
Next.

In this example, I get the Number of X Times I get a value on an Array.
I need to do something similar but each time a Cookie is found.

Any Suggestions?
Thanks

I made this For in order to watch How many Cookies I have:
for i As integer = 0 to cookies.Ubound
Msgbox cstr(i)
Next

That in fact, I have 4, counting 0(Arrays are 0 based).

Now that I want to do is the next. Get the Name of the first Cookie+Value of First Cookie+Name of 2th Cookie+Value of 2th Cookie+Name of 3th Cookie+Value of 3th Cookie.

Finally I get the order that “the cookie” is required, with this code:

Dim CookieName As String

// query list of all cookies in shared storage
dim cookies(-1) as NSHTTPCookieMBS = NSHTTPCookieStorageMBS.sharedHTTPCookieStorage.cookiesForURL(“https://portalcfdi.facturaelectronica.sat.gob.mx/ConsultaReceptor.aspx”)

// we collect values for SHCP:
dim list(-1), Valores(-1) as string

dim cookie1 as NSHTTPCookieMBS = cookies(1)
dim cookie2 as NSHTTPCookieMBS = cookies(2)
dim cookie3 as NSHTTPCookieMBS = cookies(0)
dim cookie4 as NSHTTPCookieMBS = cookies(3)

// display name:
CookieName = Cookie1.name + “=”+ Cookie1.value + “;”+ Cookie2.name + “=”+ Cookie2.value + “;”+Cookie3.name + “=”+Cookie3.value+";"+Cookie4.name+";"+Cookie4.value
Galleta.text = CookieName

But Now I’m watching that I got these values:

  1. FedAuthCONT=
  2. FedAuthCONT1=
  3. ASP .NET_SessionId
    4)_CSRFCOOKIE

But I miss “SITESERVER=ID”

So, i need to investigate how to get this value.

I’m sooo veryyyyyy happy because I probe it, despite I don’t have SiteServer=ID and voila!!! I can download the XML file from server.

Now I need to investigate if I dont put that value the XML would be malformed or something.