Help using URL in my web Site!

Discussion in 'Visual Studio' started by albanello, Oct 22, 2021.

  1. Hi

    I am using "Visual Studio 2008".

    I want to execute the URL "http://www.molottery.com/rss-num.xml" that will return a XML file, but I don't know how to get that XML file named and stored in my Web site code so I can access/use it in my Web site.

    I have been trying to accomplish this for several months with no success. ALL of my attempts have ended in a exception being thrown I can't figure out what I am doing wrong.
    Please Help!

    Note:
    I have been doing it manually:
    1) Execute URL in Browser
    2) Copy resulting XML file
    3) Paste XML file in Web Site data named "MOLRssFeed.xml"
    4) It works and is currently being used in the Web Site.
    BUT I don't want to have to do this everyday manually!

    ********
    Here is the block of code I have.
    *
    Private dstRssFeed As New DataSet

    '????????
    'Here is the code I can't figure out how to implement in the Web Site!
    '********
    'I want the Web site to execute this code:
    1) Execute URL "http://www.molottery.com/rss-num.xml"
    2) Returns XML file
    3) Name XML file "MOLRssFeed.xml"
    4) Store XML file named "MOLRssFeed.xml" in my web site so I can access/use the XML file named "MOLRssFeed.xml" in my Web site.
    ????????

    ********
    The Web site will then use XML file named "MOLRssFeed.xml in the following code:
    dstRssFeed.ReadXml(HttpContext.Current.Server.MapPath("..") & "\App_Data\MOLRssFeed.xml")

    Thank You
    Hope you can help me!
    Frank
     
  2. This is just a test to see if responses are being sent to my email!

    albanello
     
  3. Well I have access to "Post Reply" again BUT I still don't receive replies to my GMail account!
    This "Post Reply" is another test to see if my reply is going to my GMail account. Don't think it is but I have to try.

    Thanks Takeshi

    albanello
     
  4. RayH

    RayH DiscountASP.NET Lackey DiscountASP.NET Staff

    Well, you'll need to make a GET request to that URL. Then capture the results in a string and manipulate it if necessary. Then use StreamWriter or XMLWriter to output that to a .xml file. There's lots of ways to do this.
     
  5. ********
    RayH (your reply)
    ********
    "Well, you'll need to make a GET request to that URL. Then capture the results in a string and manipulate it if necessary. Then use StreamWriter or XMLWriter to output that to a .xml file.

    There's lots of ways to do this."

    ********
    albanello
    ********
    RayH I have tried "There's lots of ways to do this." over the last, at least 6 Months, all of my attempts came back throwing the same exception:
    "The underlying connection was closed: An unexpected error occurred on a send."

    I have been searching the Internet trying to find a answer to what I am trying to do, found some, tried some but could not get anything to do the URL and get the XML file saved.

    I am working with Visual Studio, Visual Basic.
    I am already doing it Manually and am trying to get the web site to do it automatically so I don't have to do it Manually every day.

    'xxxxxxxx
    'Here is a small block of the code I have been working on.
    Private dstRssFeed As New DataSet

    '????????
    'This is what I can't get to work:
    1) Execute the URL "http://www.molottery.com/rss-num.xml"
    2) Copy and Paste the XML data into a file named "MOLRssFeed.xml"
    '????????

    'I already have this working!
    dstRssFeed.ReadXml(HttpContext.Current.Server.MapPath("..") & "\App_Data\MOLRssFeed.xml")"
    'xxxxxxxx

    It seams pretty simple but as I have already said, I can not get on the correct path with the correct code.
    I am hoping you can get me started down the correct path.

    Please help me!

    Thanks
    albanello
     
  6. RayH

    RayH DiscountASP.NET Lackey DiscountASP.NET Staff

  7. Thanks RayH.

    I will try your suggested links. Hope one of them works, I'm really burnt out trying to get this code to work. Been trying different thing for 6 + months now. Been searching the internet to find a solutions for months.
    I will let you know as soon as I get the code implemented and tested.

    albanello
     
  8. ********
    albanello
    ********
    RayH here is the first block of code you suggested I try, from stackoverflow web site.
    Here is the link to stackoverflow "https://stackoverflow.com/questions/3757731/how-to-read-xml-from-remote-url-in-vb-net" that you gave me.

    My Visual Studio, Visual Basic compiler made me make changes to 2 lines of code. Changes I made are shown where the original line of code is commented out.

    I am getting the exact same exception thrown "The underlying connection was closed: An unexpected error occurred on a send." that I got with all the other blocks of code I have been trying.
    Could you please look at this code and see if you can tell me what I am doing wrong. Please!

    I marked the line of code where the exception is thrown with this text "'>>>>>>>>error thrown<<<<<<<<"

    Hope you can help me!
    Thanks
    albanello

    '********
    '********
    '********
    '********
    Try

    'Create a WebRequest to the remote site
    'Dim request As System.Net.HttpWebRequest = System.Net.HttpWebRequest.Create("https://www.texaslottery.com/export/sites/lottery/rss/tlc_latest.xml")
    Dim request As System.Net.HttpWebRequest = CType(System.Net.HttpWebRequest.Create("https://www.texaslottery.com/export/sites/lottery/rss/tlc_latest.xml"), HttpWebRequest)

    'NB! Use the following line ONLY if the web site is protected
    'request.Credentials = New System.Net.NetworkCredential("username", "password")

    'Call the remote site, and parse the data in a response object
    'Dim response As System.Net.HttpWebResponse = request.GetResponse()
    '>>>>>>>>error thrown<<<<<<<<
    'The underlying connection was closed: An unexpected error occurred on a send.
    Dim response As System.Net.HttpWebResponse = CType(request.GetResponse(), HttpWebResponse)
    '>>>>>>>>error thrown<<<<<<<<

    'Check if the response is OK (status code 200)
    If response.StatusCode = System.Net.HttpStatusCode.OK Then

    ' Parse the contents from the response to a stream object
    Dim stream As System.IO.Stream = response.GetResponseStream()
    ' Create a reader for the stream object
    Dim reader As New System.IO.StreamReader(stream)
    ' Read from the stream object using the reader, put the contents in a string
    Dim contents As String = reader.ReadToEnd()
    ' Create a new, empty XML document
    Dim document As New System.Xml.XmlDocument()

    ' Load the contents into the XML document
    document.LoadXml(contents)

    ' Now you have a XmlDocument object that contains the XML from the remote site, you can
    ' use the objects and methods in the System.Xml namespace to read the document

    Else
    ' If the call to the remote site fails, you'll have to handle this. There can be many reasons, ie. the
    ' remote site does not respond (code 404) or your username and password were incorrect (code 401)
    '
    ' See the codes in the System.Net.HttpStatusCode enumerator

    Throw New Exception("Could not retrieve document from the URL, response code: " & response.StatusCode)

    End If

    Catch ex0 As Exception
    'Exception text not shown

    End Try
    '********
    '********
    '********
    '********
     
  9. RayH

    RayH DiscountASP.NET Lackey DiscountASP.NET Staff

    Hi albanello,

    This error:

    "The underlying connection was closed: An unexpected error occurred on a send."

    Could mean that the TLS version (and ciphers) on the server you're on is not compatible with the one you're connecting to. Open a support ticket to have our support department check if the site is hosted on the latest server. If it isn't, then migrating to a newer one should hopefully fix the problem.
     
  10. Thanks RayH

    I have requested a support ticket. Today 11/14/2021

    Thanks
     

Share This Page