0

I try to read data from azure website for my android application. But when i try to reach it gives me an error.

But when i look with this website i can see json data.

I can see all json data so truely. But somehow when i enter the url my browser i can't see the data. And my url is http://tcm-test-api.azurewebsites.net/api/movie/search?term=%22Batman%22&page=1

ce.arifemre
  • 31
  • 1
  • 6
  • Try turning off Custom errors in you web config file and retry. You should at least get a detailed error message. Look at this for more info: http://stackoverflow.com/questions/13020103/webapis-messagean-error-has-occurred-on-iis7-not-in-iis-express – Much Overflow Mar 10 '16 at 11:34
  • @MuchOverflow i understood problem but i couldn't understant how can i change it because i try to read json data from this website. But i get nullPointerException but i can read json datas from other websites. – ce.arifemre Mar 10 '16 at 11:39
  • When you try the connection to this api, try setting the content-type as `application/json; charset=utf-8` It would be better if you can show how are you connecting to this service from android – Much Overflow Mar 10 '16 at 11:42
  • @MuchOverflow i try to connect like this and sorry for delaying http://paste.ubuntu.com/15340900/ – ce.arifemre Mar 10 '16 at 12:12
  • Check this stackoverflow question for how to set the content type http://stackoverflow.com/questions/10263854/java-httpclient-changing-content-type – Much Overflow Mar 10 '16 at 12:16
  • @MuchOverflow but they're using a different structure i couldn't figure out unfortunately :( – ce.arifemre Mar 10 '16 at 12:22
  • @MuchOverflow i fixed it but now i'm getting this error: The requested resource does not support http method 'POST' and i searched in stackoverflow and google but i couldn't find for android application. Could you help me? – ce.arifemre Mar 10 '16 at 12:56
  • this is a GET request so you should call it with `HttpGet` object. – Much Overflow Mar 10 '16 at 15:03
  • @MuchOverflow thanks for help you saved my time – ce.arifemre Mar 10 '16 at 15:53
  • Good to know everything worked out for you :) – Much Overflow Mar 10 '16 at 15:55
  • @MuchOverflow Please post a proper answer summarizing the fix. Currently all the details are buried in comments, and there's no answer posted (so, no ability to properly accept an answer). – David Makogon Mar 10 '16 at 16:02
  • @DavidMakogon I posted the answer as per your request – Much Overflow Mar 11 '16 at 05:24

1 Answers1

0

Try setting Content-Type to application/json;charset=utf-8 in your Http request header. In android when you create the HttpUrlConnection do it as follows

URL myURL = new URL(serviceURL);
HttpURLConnection myURLConnection = (HttpURLConnection)myURL.openConnection();
myURLConnection.setRequestMethod("GET");
myURLConnection.setRequestProperty("Content-Type", "application/json;charset=utf-8");
Much Overflow
  • 3,142
  • 1
  • 23
  • 40