Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. Mobile Development
  3. Mobile
  4. Problem fetching page in Windows Phone 8.1, VB.NET

Problem fetching page in Windows Phone 8.1, VB.NET

Scheduled Pinned Locked Moved Mobile
csharpphpdatabasewpf
7 Posts 2 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • B Offline
    B Offline
    BlackChart
    wrote on last edited by
    #1

    I'm trying to make a small app to fetch some numbers from my smarthome webpage. When trying the query in a browser like Chrome (uri: http://smarthome.trab.dk/wpf/getData.php?g=power) everything works. In the app, it just stalls - no exceptions or errors but no data either. The module is like this:

    Public uriString As String = "http://smarthome.trab.dk"
    
    Public Async Function getData(ByVal gType As String) As Tasks.Task(Of String)
        Try
            Dim Resp As String = Nothing
    
            Using httpClient As New HttpClient
                httpClient.BaseAddress = New Uri(uriString)
                httpClient.Timeout = TimeSpan.FromSeconds(10)
    
                Dim response As HttpResponseMessage = Await httpClient.GetAsync("/wpf/getData.php?g=" + gType.ToLower)
    
                Resp = Await response.Content.ReadAsStringAsync
            End Using
    
            Return Resp
        Catch webEx As HttpRequestException
            MessageBox.Show(webEx.Message)
        Catch ex As Exception
            MessageBox.Show(ex.Message)
        End Try
    End Function
    
    Public Function ACount() As String
        Dim resp As String = getData("power").Result
    
        Return "Actual: " + resp
    End Function
    

    Can anyone see what the problem is?

    Regards, Morten Trab

    D 1 Reply Last reply
    0
    • B BlackChart

      I'm trying to make a small app to fetch some numbers from my smarthome webpage. When trying the query in a browser like Chrome (uri: http://smarthome.trab.dk/wpf/getData.php?g=power) everything works. In the app, it just stalls - no exceptions or errors but no data either. The module is like this:

      Public uriString As String = "http://smarthome.trab.dk"
      
      Public Async Function getData(ByVal gType As String) As Tasks.Task(Of String)
          Try
              Dim Resp As String = Nothing
      
              Using httpClient As New HttpClient
                  httpClient.BaseAddress = New Uri(uriString)
                  httpClient.Timeout = TimeSpan.FromSeconds(10)
      
                  Dim response As HttpResponseMessage = Await httpClient.GetAsync("/wpf/getData.php?g=" + gType.ToLower)
      
                  Resp = Await response.Content.ReadAsStringAsync
              End Using
      
              Return Resp
          Catch webEx As HttpRequestException
              MessageBox.Show(webEx.Message)
          Catch ex As Exception
              MessageBox.Show(ex.Message)
          End Try
      End Function
      
      Public Function ACount() As String
          Dim resp As String = getData("power").Result
      
          Return "Actual: " + resp
      End Function
      

      Can anyone see what the problem is?

      Regards, Morten Trab

      D Offline
      D Offline
      David C Hobbyist
      wrote on last edited by
      #2

      I don't use VB. But you are expecting a numeric value and are returning a string (I think).:confused:

      David

      B 1 Reply Last reply
      0
      • D David C Hobbyist

        I don't use VB. But you are expecting a numeric value and are returning a string (I think).:confused:

        David

        B Offline
        B Offline
        BlackChart
        wrote on last edited by
        #3

        The line it strands on are:

        Dim response As HttpResponseMessage = Await httpClient.GetAsync("/wpf/getData.php?g=" + gType.ToLower)

        Way before returning anything to the app.

        D 1 Reply Last reply
        0
        • B BlackChart

          The line it strands on are:

          Dim response As HttpResponseMessage = Await httpClient.GetAsync("/wpf/getData.php?g=" + gType.ToLower)

          Way before returning anything to the app.

          D Offline
          D Offline
          David C Hobbyist
          wrote on last edited by
          #4

          I tried to work with your code but I was a bit lost(I don't do vb). But I threw this together in no time and retrieved the result You wanted.

          static void Main(string[] args)
          {
          Uri addr = new Uri( "http://smarthome.trab.dk/wpf/getData.php?g=power");
          using (WebClient client = new WebClient())
          {
          string responce = client.DownloadString (addr);
          Console.WriteLine(responce);
          Console.ReadLine();
          }
          }

          I hope this helps.

          David

          B 2 Replies Last reply
          0
          • D David C Hobbyist

            I tried to work with your code but I was a bit lost(I don't do vb). But I threw this together in no time and retrieved the result You wanted.

            static void Main(string[] args)
            {
            Uri addr = new Uri( "http://smarthome.trab.dk/wpf/getData.php?g=power");
            using (WebClient client = new WebClient())
            {
            string responce = client.DownloadString (addr);
            Console.WriteLine(responce);
            Console.ReadLine();
            }
            }

            I hope this helps.

            David

            B Offline
            B Offline
            BlackChart
            wrote on last edited by
            #5

            Did you test this on a mobile device? Errors: 'Using' operand of type 'System.Net.WebClient' must implement 'System.IDisposal' 'DownloadString' is not a member of 'System.Net.WebClient'

            1 Reply Last reply
            0
            • D David C Hobbyist

              I tried to work with your code but I was a bit lost(I don't do vb). But I threw this together in no time and retrieved the result You wanted.

              static void Main(string[] args)
              {
              Uri addr = new Uri( "http://smarthome.trab.dk/wpf/getData.php?g=power");
              using (WebClient client = new WebClient())
              {
              string responce = client.DownloadString (addr);
              Console.WriteLine(responce);
              Console.ReadLine();
              }
              }

              I hope this helps.

              David

              B Offline
              B Offline
              BlackChart
              wrote on last edited by
              #6

              Your example lead me to this, found on another site:

              Public Sub getData(ByVal gType As String)
              Dim addr As Uri = New Uri("http://smarthome.trab.dk/wpf/getData.php?g=" + gType)

              Dim client As New WebClient()
              AddHandler client.DownloadStringCompleted, AddressOf client\_DownloadStringCompleted
              client.DownloadStringAsync(addr)
              

              End Sub

              Private Sub client_DownloadStringCompleted(sender As Object, e As DownloadStringCompletedEventArgs)

              Dim data As String = e.Result
              MessageBox.Show(data)
              

              End Sub

              And it returns the data :)

              D 1 Reply Last reply
              0
              • B BlackChart

                Your example lead me to this, found on another site:

                Public Sub getData(ByVal gType As String)
                Dim addr As Uri = New Uri("http://smarthome.trab.dk/wpf/getData.php?g=" + gType)

                Dim client As New WebClient()
                AddHandler client.DownloadStringCompleted, AddressOf client\_DownloadStringCompleted
                client.DownloadStringAsync(addr)
                

                End Sub

                Private Sub client_DownloadStringCompleted(sender As Object, e As DownloadStringCompletedEventArgs)

                Dim data As String = e.Result
                MessageBox.Show(data)
                

                End Sub

                And it returns the data :)

                D Offline
                D Offline
                David C Hobbyist
                wrote on last edited by
                #7

                Glad You found an answer. Good luck!

                David

                1 Reply Last reply
                0
                Reply
                • Reply as topic
                Log in to reply
                • Oldest to Newest
                • Newest to Oldest
                • Most Votes


                • Login

                • Don't have an account? Register

                • Login or register to search.
                • First post
                  Last post
                0
                • Categories
                • Recent
                • Tags
                • Popular
                • World
                • Users
                • Groups