Solved

RSS Feed with password...

Posted on 2007-12-04
14
450 Views
Last Modified: 2013-11-18
I have code to read an RSS feed into a page, via classic ASP and MSXML2.Domdocument.

We have an intranet here that is password protected, what I'd like to know is, how can I pass my username/password to my code so I can view this feed locally.  I am using local IIS, and the code follows...
Public Function strGetRSS(strURL, strFeedsToShow)

	    'Let's set our object

	    dim xmlDom, nodeCol, oNode, oChildNode

	    set xmlDom = Server.CreateObject("MSXML2.Domdocument")

		    xmlDOM.async = False

		    'Set our HTTP Request

		    call xmlDom.setProperty("ServerHTTPRequest", true)

		    xmlDom.async = False

		    'Now we load the document

		    call xmlDom.load(strURL)

		    'Check for elements

		    if not xmlDom.documentElement is nothing then

			    set nodeCol = xmlDom.documentElement.selectNodes("channel/item")

				    'Start a count of the articles to display

				    i = 0			  

				    'Start to loop through each article

				    for each oNode in nodeCol

					    'This number sets the number of articles to display

					    if i < strFeedsToShow then

						    Response.Write("<div>" & vbCrLf)

						    'The Link

						    set oChildNode = oNode.selectSingleNode("link")

							    if not oChildNode is nothing then

								    strRSSLink = oChildNode.text

							    end if

						    set oChildNode = nothing

						    'The Title

						    set oChildNode = oNode.selectSingleNode("title")

							    if not oChildNode is nothing then

								    strRSSTitle = Server.HTMLEncode(oChildNode.text)

								    strGetRSS = strGetRSS & "<div class='rssTitle'><a href=""#"" onclick=""loadurl('/golfTipsMagModule2/content.asp?url=" & server.URLEncode(strRSSLink) & "&pt="&Request.QueryString("c")&"&title="&server.URLEncode(strRSSTitle)&"','rssFull');return false;"">" & strRSSTitle & "</a></div>"

							    end if

						    set oChildNode = nothing

						    'Published Date

						    set oChildNode = oNode.selectSingleNode("pubDate")

							    if not oChildNode is nothing then

								    strRSSPubDate = Server.HTMLEncode(oChildNode.text)

								    strGetRSS = strGetRSS & "<div class='rssDate'>" & strRSSPubDate & "</div>" & vbCrLf

							    end if

						    set oChildNode = nothing

						    'The Description

						    set oChildNode = oNode.selectSingleNode("description")

							    if not oChildNode is nothing then

								    strRSSDesc = oChildNode.text

								    strGetRSS = strGetRSS & "<div class='rssDesc'>" & strRSSDesc & "</div>"

							    end if

						    set oChildNode = nothing

						    'Add 1 to the article count number

						    i = i + 1

						    strGetRSS = strGetRSS & "</div>" & vbCrLf

					    end if

				    next

			    set nodeCol = nothing

		    else

			    strGetRSS = strGetRSS & strPANError & vbCrLf

		    end if

	    set xmlDom = nothing

    End Function

Open in new window

0
Comment
Question by:kevp75
  • 6
  • 4
  • 3
  • +1
14 Comments
 
LVL 36

Expert Comment

by:Loganathan Natarajan
ID: 20402617
>> how can I pass my username/password to my code

if INTERNET is connected, the code will fetch the feeds results... not sure about your intranet setup to pass the authentication details to access internet..,
0
 
LVL 14

Expert Comment

by:_Stilgar_
ID: 20402630
That depands on the password type. Try formatting your URL (that you pass as strURL) as follows:

http://username:password@ip_or_url/folder/file.rss

Stilgar.
0
 
LVL 28

Expert Comment

by:sybe
ID: 20402658
You can use the "Microsoft.XMLHTTP" object, and use the same object twice.

First time you submit your username/password to the login script. The object is then logged on (it will have cookies, even a session-cookie). Then use the same object (which is now logged in) to get the code for the RSS. After that you'll have to process the returned RSS into an XML-object, but I guess that is not problematic for you.
0
 
LVL 28

Expert Comment

by:sybe
ID: 20402707
I use this function sometimes, but you might want to adapt it for your own purpose
Function LoginAndGetUrl(ByVal sLoginUrl, ByVal sLoginData, ByVal sLoginMethod, ByVal sUrlToGet, ByVal sUrlData, ByVal sGetUrlMethod)

    Dim oXMLHttpRequest
 

    Set oXMLHttpRequest = Server.CreateObject("Microsoft.XMLHTTP")
 

    ' first login in (and get a cookie)

    If LCase(sLoginMethod) = "post" Then

        oXMLHttpRequest.Open "POST", sLoginUrl, False

        oXMLHttpRequest.setRequestHeader "Content-Type", "application/x-www-form-urlencoded"

        oXMLHttpRequest.Send Unescape(sLoginData)

    Else

        oXMLHttpRequest.open "GET", sLoginUrl & "?" & sLoginData, False

        oXMLHttpRequest.send

    End If
 

    ' then - using the same object, get the url
 

    If LCase(sGetUrlMethod) = "post" Then

        oXMLHttpRequest.Open "POST", sUrlToGet, False

        oXMLHttpRequest.setRequestHeader "Content-Type", "application/x-www-form-urlencoded"

        oXMLHttpRequest.Send Unescape(sUrlData)

    Else

        oXMLHttpRequest.open "GET", sUrlToGet & "?" & sUrlData, False

        oXMLHttpRequest.send

    End If
 

    LoginAndGetUrl = oXMLHttpRequest.responseText

    Set oXMLHttpRequest = Nothing

End Function

Open in new window

0
 
LVL 25

Author Comment

by:kevp75
ID: 20403841
it is an intranet site that uses Windows Auth.
0
 
LVL 25

Author Comment

by:kevp75
ID: 20403851
@Stilgar.....method did not work.   The site I am using is localhost to pull the feed from our company intranet
0
 
LVL 28

Accepted Solution

by:
sybe earned 250 total points
ID: 20404192
> it is an intranet site that uses Windows Auth.

You mean integrated authentication (which is I believe IE only)?

You can of course also grab the RSS in the client, with a clientside javascript or vbscript. Because if the browser is logged in automatically, then any client script calls will use that authentication.
0
Better Security Awareness With Threat Intelligence

See how one of the leading financial services organizations uses Recorded Future as part of a holistic threat intelligence program to promote security awareness and proactively and efficiently identify threats.

 
LVL 25

Author Comment

by:kevp75
ID: 20404305
I mean windows authentication.  I am grabbing the RSS in the client with serverside vbscript, and though I have added the 2 sites to my trusted sites, I can open the intranet site without logging in now, I cannot get the feed to show
0
 
LVL 25

Author Comment

by:kevp75
ID: 20404633
ok....so...know of any good javascript feed readers?
0
 
LVL 14

Assisted Solution

by:_Stilgar_
_Stilgar_ earned 250 total points
ID: 20404689
Well, finding a javascript piece is really easy:

http://momche.net/publish/article.php?page=rssload
http://www.xml.com/pub/a/2006/09/13/rss-and-ajax-a-simple-news-reader.html

but I'm still trying to understand what exactly goes wrong at your end. How is the path you're using looks like - an IP URL like the one I proposed? a file path starting with \\? and what does it mean "I cannot get the feed to show" - what do you get?

Stilgar.
0
 
LVL 25

Author Comment

by:kevp75
ID: 20404719
it's a URL http://intranet.oursite.com/rssfeed....

the feed does not display, all I get is a blank page...
0
 
LVL 14

Expert Comment

by:_Stilgar_
ID: 20404899
You sure it doesn't get loaded? debug your code, see if its your code's fault or the feed's

Stilgar.
0
 
LVL 25

Author Comment

by:kevp75
ID: 20405117
Stilgar....c'mon now.....

it does not load.  I've put in alerts/response.writes on the .xml and strGetRSS and nothing comes up (except the null for the alert)

I'm going to use that first link you posted  (since I already tried it for this feed, and it works.)

The issue is, because the intranet site uses Windows Authentication, I cannot use server-side code to do this.  I have to use client side code (as the browser is already setup to trust the site(s))
0
 
LVL 14

Expert Comment

by:_Stilgar_
ID: 20405210
:)
0

Featured Post

Find Ransomware Secrets With All-Source Analysis

Ransomware has become a major concern for organizations; its prevalence has grown due to past successes achieved by threat actors. While each ransomware variant is different, we’ve seen some common tactics and trends used among the authors of the malware.

Join & Write a Comment

Suggested Solutions

Introduction Knockoutjs (Knockout) is a JavaScript framework (Model View ViewModel or MVVM framework).   The main ideology behind Knockout is to control from JavaScript how a page looks whilst creating an engaging user experience in the least …
JavaScript has plenty of pieces of code people often just copy/paste from somewhere but never quite fully understand. Self-Executing functions are just one good example that I'll try to demystify here.
Viewers will learn about the regular for loop in Java and how to use it. Definition: Break the for loop down into 3 parts: Syntax when using for loops: Example using a for loop:
The viewer will the learn the benefit of plain text editors and code an HTML5 based template for use in further tutorials.

746 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

10 Experts available now in Live!

Get 1:1 Help Now