Excel and Atom Feeds

arkusM

Well-known Member
Joined
Apr 12, 2007
Messages
560
Does anyone know how to access Atom data feeds through Excel? The data I am trying to get at is on a secure server, so I also need authentication, but I am having trouble finding examples through a google search.

Cheers
 
Hey, Tried your new code to no avail, still getting the source code for the login page itself. I did make the corecction you mentioned above.
Though it does seem to go to the website... just not submit the username and password...
I will try on another computer.
Cheers
 
Upvote 0
There's no point in trying it on another computer. If you're receiving the login page, it means the server didn't like something in the request and redirect the client back to the login page. It means there must be something wrong with the request, but I am not sure what, sorry. Will take another look at it later.

If I can't figure it out, then it totally makes sense doing it another way, by IE automation.
 
Upvote 0
There's no point in trying it on another computer. If you're receiving the login page, it means the server didn't like something in the request and redirect the client back to the login page. It means there must be something wrong with the request, but I am not sure what, sorry. Will take another look at it later.

If I can't figure it out, then it totally makes sense doing it another way, by IE automation.

No matter the outcome, I really appreicate your efforts, thank you for taking the time to go through this.

Mark
 
Upvote 0
Mark, there was a big mistake in my code. The second request should've been POST, of course, not GET. :oops: I am re-posting the entire corrected code.

Code:
Public Type Ngx_Session
    OldSessionID As String
    SessionID As String
    FormActionURL As String
    LtValue As String
End Type

Sub Test_login()
Dim mySession As Ngx_Session
    Ngx_EstSession mySession
'    Debug.Print mySession.FormActionURL
'    Debug.Print mySession.SessionID
'    Debug.Print mySession.LtValue
    Ngx_Login mySession, "myusername123", "mypassword123"
End Sub

Private Sub Ngx_EstSession(sess As Ngx_Session)
Dim xmlReq As ServerXMLHTTP
Dim servResp As String
Dim pos As Long

Set xmlReq = New ServerXMLHTTP

xmlReq.Open "GET", "https://secure.ngx.com/ngxcs/home.html", False
xmlReq.setRequestHeader "User-Agent", "Mozilla/4.0 (compatible; MSIE 8.0; Windows NT 5.1; Trident/4.0; .NET CLR 1.1.4322; .NET CLR 2.0.50727; .NET CLR 3.0.4506.2152; .NET CLR 3.5.30729; .NET4.0C; .NET4.0E)"
xmlReq.setRequestHeader "Connection", "keep-alive"
xmlReq.setRequestHeader "Host", "secure.ngx.com/"
xmlReq.send

If xmlReq.Status <> 200 Then MsgBox "Error occured: " & xmlReq.statusText: Exit Sub

servResp = xmlReq.responseText

sess.SessionID = Split(Replace(xmlReq.getResponseHeader("Set-Cookie"), "JSESSIONID=", ""), ";")(0)

pos = InStr(1, servResp, "action=""", 1) + 8
sess.FormActionURL = "https://secure.ngx.com" & Mid(servResp, pos, InStr(pos, servResp, Chr(34), 1) - pos)
pos = 0

pos = InStr(1, servResp, "name=""lt"" value=""", 1) + 17
sess.LtValue = Mid(servResp, pos, InStr(pos, servResp, Chr(34), 1) - pos)

pos = InStr(1, servResp, "action=""/", 1) + 8
sess.OldSessionID = Right(Mid(servResp, pos, InStr(pos, servResp, Chr(34), 1) - pos), 32)

End Sub


Private Sub Ngx_Login(sess As Ngx_Session, usrName As String, pwd As String)
Dim xmlReq As ServerXMLHTTP
Dim postBody As String

postBody = "username=" & usrName & "&" & _
            "password=" & pwd & "&" & _
            "lt=" & sess.LtValue & _
            "&_eventId=submit&submit=Login"

Set xmlReq = New ServerXMLHTTP
xmlReq.Open "POST", sess.FormActionURL, , False
xmlReq.setRequestHeader "User-Agent", "Mozilla/4.0 (compatible; MSIE 8.0; Windows NT 5.1; Trident/4.0; .NET CLR 1.1.4322; .NET CLR 2.0.50727; .NET CLR 3.0.4506.2152; .NET CLR 3.5.30729; .NET4.0C; .NET4.0E)"
xmlReq.setRequestHeader "Connection", "keep-alive"
xmlReq.setRequestHeader "Referer", "https://secure.ngx.com/sso/login?service=https%3A%2F%2Fsecure.ngx.com%3A443%2Fngxcs%2Fj_spring_cas_security_check%3Bjsessionid%3D" & sess.OldSessionID
xmlReq.setRequestHeader "Cookie", "JSESSIONID=" & sess.SessionID
xmlReq.setRequestHeader "Host", "secure.ngx.com/"
xmlReq.setRequestHeader "Content-Type", "application/x-www-form-urlencoded"
xmlReq.setRequestHeader "Content-Length", Len(postBody)
xmlReq.send postBody

If xmlReq.Status <> 200 Then MsgBox "Error occured: " & xmlReq.statusText: Exit Sub

servResp = xmlReq.responseText

Dim DataObj As New MSForms.DataObject
DataObj.SetText servResp
DataObj.PutInClipboard

End Sub

Don't forget to change username and password values in 'Test_login' sub.
 
Upvote 0
Mark, there was a big mistake in my code. The second request should've been POST, of course, not GET. :oops: I am re-posting the entire corrected code.

Code:
Public Type Ngx_Session
    OldSessionID As String
    SessionID As String
    FormActionURL As String
    LtValue As String
End Type

Sub Test_login()
Dim mySession As Ngx_Session
    Ngx_EstSession mySession
'    Debug.Print mySession.FormActionURL
'    Debug.Print mySession.SessionID
'    Debug.Print mySession.LtValue
    Ngx_Login mySession, "myusername123", "mypassword123"
End Sub

Private Sub Ngx_EstSession(sess As Ngx_Session)
Dim xmlReq As ServerXMLHTTP
Dim servResp As String
Dim pos As Long

Set xmlReq = New ServerXMLHTTP

xmlReq.Open "GET", "https://secure.ngx.com/ngxcs/home.html", False
xmlReq.setRequestHeader "User-Agent", "Mozilla/4.0 (compatible; MSIE 8.0; Windows NT 5.1; Trident/4.0; .NET CLR 1.1.4322; .NET CLR 2.0.50727; .NET CLR 3.0.4506.2152; .NET CLR 3.5.30729; .NET4.0C; .NET4.0E)"
xmlReq.setRequestHeader "Connection", "keep-alive"
xmlReq.setRequestHeader "Host", "secure.ngx.com/"
xmlReq.send

If xmlReq.Status <> 200 Then MsgBox "Error occured: " & xmlReq.statusText: Exit Sub

servResp = xmlReq.responseText

sess.SessionID = Split(Replace(xmlReq.getResponseHeader("Set-Cookie"), "JSESSIONID=", ""), ";")(0)

pos = InStr(1, servResp, "action=""", 1) + 8
sess.FormActionURL = "https://secure.ngx.com" & Mid(servResp, pos, InStr(pos, servResp, Chr(34), 1) - pos)
pos = 0

pos = InStr(1, servResp, "name=""lt"" value=""", 1) + 17
sess.LtValue = Mid(servResp, pos, InStr(pos, servResp, Chr(34), 1) - pos)

pos = InStr(1, servResp, "action=""/", 1) + 8
sess.OldSessionID = Right(Mid(servResp, pos, InStr(pos, servResp, Chr(34), 1) - pos), 32)

End Sub


Private Sub Ngx_Login(sess As Ngx_Session, usrName As String, pwd As String)
Dim xmlReq As ServerXMLHTTP
Dim postBody As String

postBody = "username=" & usrName & "&" & _
            "password=" & pwd & "&" & _
            "lt=" & sess.LtValue & _
            "&_eventId=submit&submit=Login"

Set xmlReq = New ServerXMLHTTP
xmlReq.Open "POST", sess.FormActionURL, , False
xmlReq.setRequestHeader "User-Agent", "Mozilla/4.0 (compatible; MSIE 8.0; Windows NT 5.1; Trident/4.0; .NET CLR 1.1.4322; .NET CLR 2.0.50727; .NET CLR 3.0.4506.2152; .NET CLR 3.5.30729; .NET4.0C; .NET4.0E)"
xmlReq.setRequestHeader "Connection", "keep-alive"
xmlReq.setRequestHeader "Referer", "https://secure.ngx.com/sso/login?service=https%3A%2F%2Fsecure.ngx.com%3A443%2Fngxcs%2Fj_spring_cas_security_check%3Bjsessionid%3D" & sess.OldSessionID
xmlReq.setRequestHeader "Cookie", "JSESSIONID=" & sess.SessionID
xmlReq.setRequestHeader "Host", "secure.ngx.com/"
xmlReq.setRequestHeader "Content-Type", "application/x-www-form-urlencoded"
xmlReq.setRequestHeader "Content-Length", Len(postBody)
xmlReq.send postBody

If xmlReq.Status <> 200 Then MsgBox "Error occured: " & xmlReq.statusText: Exit Sub

servResp = xmlReq.responseText

Dim DataObj As New MSForms.DataObject
DataObj.SetText servResp
DataObj.PutInClipboard

End Sub

Don't forget to change username and password values in 'Test_login' sub.

That go me in! excellent. Thank you so much for your effort and patience.

General questions regarding xml:
I do have some documentation on the variable names to get the info I need, but where would you put the instructions to get the data I want?
Would you send another xmlReq "GET" request? (Ithink that is what the documentation I have says) If so would the variables I want go in the "RequestHeader"? (I am tring to set date variables) and would I have to set it up the same/similair way that you setup the Ngx_EstSession?


Again, thank you so much for your help.
 
Upvote 0
Mark,

Yes, another GET request needs to be sent where an URL for the xml feed would be specified in the .Open method of xmlReq.
Session ID must be attached in the header of the request like this:
Code:
xmlReq.setRequestHeader "Cookie", "JSESSIONID=" & sess.SessionID
Use other request headers from 'Ngx_EstSession' sub.
Let me know how it goes.
 
Upvote 0
poolhall,

So I didn't get back sooner I have been away for two weeks...

thank you for all your help. I was able to log into the secure area and with some help from the company who's data I am accessing found the proper url to look at. Now I just need to write the algorithm to extract the data... and get IT to allow access to the server programmatically...

So again thank you so much for you assistance.

Cheers,

Mark
 
Upvote 0

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top