• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Http request not sending

 
Ranch Hand
Posts: 105
2
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi I am trying to send data via http POST request to Microsoft Azure IoT Central.

I made a small app with a click counter and am trying to send the count as data but nothing is appearing on IoT Central, when I tried in Postman it worked.

Here is the code I am working with:


Any ideas would be great, thanks so much!
 
Rancher
Posts: 5008
38
  • Likes 2
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Add a call to printStackTrace in the catch block at line 50 to show if there are any exceptions thrown in the try block.
 
Marshal
Posts: 4501
572
VSCode Eclipse IDE TypeScript Redhat MicroProfile Quarkus Java Linux
  • Likes 2
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Glenda Karen wrote:Any ideas would be great, thanks so much!


I would start by not ignoring any exceptions which may get thrown in your onClick handler.  At a minimum log the exception class name and message contents.
 
Ron McLeod
Marshal
Posts: 4501
572
VSCode Eclipse IDE TypeScript Redhat MicroProfile Quarkus Java Linux
  • Likes 2
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Also, I would log the response status as well - maybe at a DEBUG level: response.getStatusLine().toString()
 
Glenda Karen
Ranch Hand
Posts: 105
2
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks so much for the replies!
I added a printStackTrace and got:
 
Glenda Karen
Ranch Hand
Posts: 105
2
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I get an error Cannot resolve method 'getStatusLine' in 'HttpResponse' when trying to response.getStatusLine().toString()
 
Ron McLeod
Marshal
Posts: 4501
572
VSCode Eclipse IDE TypeScript Redhat MicroProfile Quarkus Java Linux
  • Likes 2
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
You are performing a network operation in a UI thread which could lead to the UI becoming unresponsive.  Android throws a NetworkOnMainThreadException to remind you of this.

I'm not sure what the current best practice is for performing asynchronous HTTP.  It was common to use AsyncTask, but it looks like that has been deprecated.
 
Ron McLeod
Marshal
Posts: 4501
572
VSCode Eclipse IDE TypeScript Redhat MicroProfile Quarkus Java Linux
  • Likes 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Retrofit might be an option for you.  I haven't done any much Android development recently, so I'm not sure what else to suggest.
 
Glenda Karen
Ranch Hand
Posts: 105
2
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks so much for the suggestions and help!
 
reply
    Bookmark Topic Watch Topic
  • New Topic