Help ! Json Data Displays On Browser But Returns Error (500) Via Httpurlconn - Programming - Nairaland
Nairaland Forum › Science/Technology › Programming › Help ! Json Data Displays On Browser But Returns Error (500) Via Httpurlconn (1307 Views)
| Help ! Json Data Displays On Browser But Returns Error (500) Via Httpurlconn by emidizy(op): 4:34pm On Jun 05, 2018*. Modified: 6:21pm On Jun 05, 2018 |
I am trying to get a json data at http://www.my currency.net/service/rates which contains a valid json data as I confirmed using my browser but returns an error 500 when I try to get the page using HttpUrlConnection. See screenshot of my code below; Note: I have been using the code to get a success response from same url but it suddenly started returning Internal Server Error. public JSONObject MakeHttpRequest() { try { URL url = new URL(" http://www.mycurrency.net/service/rates " ); HttpURLConnection httpCon = (HttpURLConnection) url.openConnection(); httpCon.setRequestMethod( "GET" ); httpCon.connect(); Log.d("cryptox", String.valueOf(httpCon.getResponseCode() + " : " + httpCon.getResponseMessage() + " : "+ httpCon.getErrorStream())); InputStream inputStream = new BufferedInputStream(httpCon.getInputStream()); //CREATE A BUFFERED READER TO CONVERT THE BYTES inputStream to char BufferedReader reader = new BufferedReader(new InputStreamReader(inputStream)); StringBuilder sBuilder = new StringBuilder(); String line = null; jsonString = null; try{ while((line = reader.readLine()) != null){ sBuilder.append(line).append("\n" ); } jsonString = sBuilder.toString(); jsonObject = new JSONObject(jsonString); } catch (IOException ex){ ex.printStackTrace(); } catch (JSONException ex){ ex.printStackTrace(); } finally { inputStream.close(); } } catch (MalformedURLException ex){ ex.printStackTrace(); } catch(ProtocolException ex){ ex.printStackTrace(); } catch (IOException ex){ ex.printStackTrace(); } return jsonObject; } LOGCAT 06-05 14:24:02.249 23278-23437/com.cyptoxchange.cryptox D/cryptox: 500 : Internal Server Error : buffer(com.android.okhttp.internal.http.HttpConnection$ChunkedSource@5f6823).inputStream() 06-05 14:24:02.249 23278-23437/com.cyptoxchange.cryptox W/System.err: java.io.FileNotFoundException: http://www.mycurrency.net/service/rates 06-05 14:24:02.253 17887-17887/? I/: service_to_fd shell:cat /proc/23278/stat 06-05 14:24:02.255 17887-17887/? I/: subprocess creation successful: local_socket_fd=23, pid=23717 06-05 14:24:02.271 17887-23718/? I/: post waitpid (pid=23717) status=0000 06-05 14:24:02.287 23278-23437/com.cyptoxchange.cryptox W/System.err: at com.android.okhttp.internal.huc.HttpURLConnectionImpl.getInputStream(HttpURLConnectionImpl.java:250) 06-05 14:24:02.287 23278-23437/com.cyptoxchange.cryptox W/System.err: at com.cyptoxchange.cryptox.HttpHandler.MakeHttpRequest(HttpHandler.java:32) Any help with the cause of this will be much appreciated. Thanks.! |
| Re: Help ! Json Data Displays On Browser But Returns Error (500) Via Httpurlconn by onwards: 5:43pm On Jun 05, 2018 |
The link returns a 404. It isn't routing to a downloadable json file. Are you sure you are consuming a valid JSON api? |
| Re: Help ! Json Data Displays On Browser But Returns Error (500) Via Httpurlconn by emidizy(op): 6:23pm On Jun 05, 2018 |
onwards:The link returns a valid json on my uc & chrome web browser but on opera and phx browsers it returns error 500. I m just confused. And I couldn't find find the api documentation. |
| Re: Help ! Json Data Displays On Browser But Returns Error (500) Via Httpurlconn by webapi: 8:38pm On Jun 05, 2018 |
emidizy:Have you tried it on POSTMAN? |
| Re: Help ! Json Data Displays On Browser But Returns Error (500) Via Httpurlconn by emidizy(op): 9:09pm On Jun 05, 2018 |
webapi:Not yet. I just heard about postman. How would it help ? |
| Re: Help ! Json Data Displays On Browser But Returns Error (500) Via Httpurlconn by webapi: 2:23am On Jun 06, 2018 |
emidizy:It helps test run json output request endpoints... Be it GET, POST, PUT, DELETE and so many other requests. |
| Re: Help ! Json Data Displays On Browser But Returns Error (500) Via Httpurlconn by emidizy(op): 8:52am On Jun 06, 2018*. Modified: 9:36am On Jun 06, 2018 |
webapi:No luck with postman ! It throws same error response. See attached scrernshots. I don't understand why & how some browsers like uc web and chrome are able to pull a success response from same URL. Funny enough I tested the URL with Jsonlint (online json validator) and it validated the URL.
|
Help With This Json Data • Python JSON | Encoding And Decoding JSON Data With Python • How To Parse Json Data In Golang • 2 • 3 • 4
I Need A Very Good Hacker For A Very Interesting Job Life Changing • Don't Be A Framework-infected Programmer • 10 Or More Programmers Needed To Co-found A Big Technology Company