HttpURLConnection with JSON on Android 9, API 28 [duplicate]How to allow all Network connection types HTTP and HTTPS in Android (9) Pie?How do I format a Microsoft JSON date?Can comments be used in JSON?How can I pretty-print JSON in a shell script?What is the correct JSON content type?Close/hide the Android Soft KeyboardWhy is the Android emulator so slow? How can we speed up the Android emulator?Why does Google prepend while(1); to their JSON responses?Is there a unique Android device ID?How do I POST JSON data with Curl from a terminal/commandline to Test Spring REST?Proper use cases for Android UserManager.isUserAGoat()?

Why might one *not* want to use a capo?

Why nature prefers simultaneous events?

STM32 cannot reach individual registers and pins as PIC

Should I use the words "pyromancy" and "necromancy" even if they don't mean what people think they do?

Why does glibc's strlen need to be so complicated to run quickly?

How is std::optional never "valueless by exception"?

What is the name of this plot that has rows with two connected dots?

Did the Apollo Guidance Computer really use 60% of the world's ICs in 1963?

Why doesn't Starship have four landing legs?

Why did Lucius make a deal out of Buckbeak hurting Draco but not about Draco being turned into a ferret?

Is this position a forced win for Black after move 14?

Another "Ask One Question" Question

What checks exist against overuse of presidential pardons in the USA?

Is the internet in Madagascar faster than in UK?

Why can't you say don't instead of won't?

What to do about my 1-month-old boy peeing through diapers?

Term used to describe a person who predicts future outcomes

Alternatives to Network Backup

Spicing up a moment of peace

Why does AM radio react to IR remote?

What's the point of fighting monsters in Zelda BotW?

How could a self contained organic body propel itself in space

Heat output from a 200W electric radiator?

Fantasy Macro Economics: What would Merfolk trade for?



HttpURLConnection with JSON on Android 9, API 28 [duplicate]


How to allow all Network connection types HTTP and HTTPS in Android (9) Pie?How do I format a Microsoft JSON date?Can comments be used in JSON?How can I pretty-print JSON in a shell script?What is the correct JSON content type?Close/hide the Android Soft KeyboardWhy is the Android emulator so slow? How can we speed up the Android emulator?Why does Google prepend while(1); to their JSON responses?Is there a unique Android device ID?How do I POST JSON data with Curl from a terminal/commandline to Test Spring REST?Proper use cases for Android UserManager.isUserAGoat()?






.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty margin-bottom:0;








2
















This question already has an answer here:



  • How to allow all Network connection types HTTP and HTTPS in Android (9) Pie?

    6 answers



I'm trying to use HttpURLConnection in Android 9, API 28. It works on Android 8.0.0, API 26, but not on API 28.



 JSONObject jsonObject = new JSONObject();
jsonObject.accumulate("name", name);
String json = jsonObject.toString();

URL url = new URL("http://website_link");
HttpURLConnection urlConnection = (HttpURLConnection) url.openConnection();
urlConnection.setDoOutput(true);
urlConnection.setRequestMethod("POST");
urlConnection.setRequestProperty("Content-Type", "application/json; charset=UTF-8");

OutputStream os = urlConnection.getOutputStream();
os.write(json.getBytes("UTF-8"));
os.close();

InputStream inputStream = new BufferedInputStream(urlConnection.getInputStream());
BufferedReader reader = new BufferedReader(new InputStreamReader(inputStream, Charset.forName("utf-8")), 8);
String line;
json = "";

while ((line = reader.readLine()) != null)
json += line;


inputStream.close();

jsonObject = new JSONObject(json);

inputStream.close();
urlConnection.disconnect();

...


I tried to use Log.d to see what code is not executed and I saw that it stops on OutputStream os = urlConnection.getOutputStream();



Do you know where is the problem?










share|improve this question














marked as duplicate by Michał Ziober, tir38, gdlmx, Matteo Baldi, Mạnh Quyết Nguyễn Mar 28 at 10:22


This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.



















  • How is this "not working"? Crash? Unexpected behavior?

    – tir38
    Mar 28 at 2:21











  • As I wrote it stops on OutputStream os = urlConnection.getOutputStream();. That part is not executed and nothing happens, app doesn't crash, just that part is not executed.

    – user3566569
    Mar 28 at 13:09

















2
















This question already has an answer here:



  • How to allow all Network connection types HTTP and HTTPS in Android (9) Pie?

    6 answers



I'm trying to use HttpURLConnection in Android 9, API 28. It works on Android 8.0.0, API 26, but not on API 28.



 JSONObject jsonObject = new JSONObject();
jsonObject.accumulate("name", name);
String json = jsonObject.toString();

URL url = new URL("http://website_link");
HttpURLConnection urlConnection = (HttpURLConnection) url.openConnection();
urlConnection.setDoOutput(true);
urlConnection.setRequestMethod("POST");
urlConnection.setRequestProperty("Content-Type", "application/json; charset=UTF-8");

OutputStream os = urlConnection.getOutputStream();
os.write(json.getBytes("UTF-8"));
os.close();

InputStream inputStream = new BufferedInputStream(urlConnection.getInputStream());
BufferedReader reader = new BufferedReader(new InputStreamReader(inputStream, Charset.forName("utf-8")), 8);
String line;
json = "";

while ((line = reader.readLine()) != null)
json += line;


inputStream.close();

jsonObject = new JSONObject(json);

inputStream.close();
urlConnection.disconnect();

...


I tried to use Log.d to see what code is not executed and I saw that it stops on OutputStream os = urlConnection.getOutputStream();



Do you know where is the problem?










share|improve this question














marked as duplicate by Michał Ziober, tir38, gdlmx, Matteo Baldi, Mạnh Quyết Nguyễn Mar 28 at 10:22


This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.



















  • How is this "not working"? Crash? Unexpected behavior?

    – tir38
    Mar 28 at 2:21











  • As I wrote it stops on OutputStream os = urlConnection.getOutputStream();. That part is not executed and nothing happens, app doesn't crash, just that part is not executed.

    – user3566569
    Mar 28 at 13:09













2












2








2









This question already has an answer here:



  • How to allow all Network connection types HTTP and HTTPS in Android (9) Pie?

    6 answers



I'm trying to use HttpURLConnection in Android 9, API 28. It works on Android 8.0.0, API 26, but not on API 28.



 JSONObject jsonObject = new JSONObject();
jsonObject.accumulate("name", name);
String json = jsonObject.toString();

URL url = new URL("http://website_link");
HttpURLConnection urlConnection = (HttpURLConnection) url.openConnection();
urlConnection.setDoOutput(true);
urlConnection.setRequestMethod("POST");
urlConnection.setRequestProperty("Content-Type", "application/json; charset=UTF-8");

OutputStream os = urlConnection.getOutputStream();
os.write(json.getBytes("UTF-8"));
os.close();

InputStream inputStream = new BufferedInputStream(urlConnection.getInputStream());
BufferedReader reader = new BufferedReader(new InputStreamReader(inputStream, Charset.forName("utf-8")), 8);
String line;
json = "";

while ((line = reader.readLine()) != null)
json += line;


inputStream.close();

jsonObject = new JSONObject(json);

inputStream.close();
urlConnection.disconnect();

...


I tried to use Log.d to see what code is not executed and I saw that it stops on OutputStream os = urlConnection.getOutputStream();



Do you know where is the problem?










share|improve this question















This question already has an answer here:



  • How to allow all Network connection types HTTP and HTTPS in Android (9) Pie?

    6 answers



I'm trying to use HttpURLConnection in Android 9, API 28. It works on Android 8.0.0, API 26, but not on API 28.



 JSONObject jsonObject = new JSONObject();
jsonObject.accumulate("name", name);
String json = jsonObject.toString();

URL url = new URL("http://website_link");
HttpURLConnection urlConnection = (HttpURLConnection) url.openConnection();
urlConnection.setDoOutput(true);
urlConnection.setRequestMethod("POST");
urlConnection.setRequestProperty("Content-Type", "application/json; charset=UTF-8");

OutputStream os = urlConnection.getOutputStream();
os.write(json.getBytes("UTF-8"));
os.close();

InputStream inputStream = new BufferedInputStream(urlConnection.getInputStream());
BufferedReader reader = new BufferedReader(new InputStreamReader(inputStream, Charset.forName("utf-8")), 8);
String line;
json = "";

while ((line = reader.readLine()) != null)
json += line;


inputStream.close();

jsonObject = new JSONObject(json);

inputStream.close();
urlConnection.disconnect();

...


I tried to use Log.d to see what code is not executed and I saw that it stops on OutputStream os = urlConnection.getOutputStream();



Do you know where is the problem?





This question already has an answer here:



  • How to allow all Network connection types HTTP and HTTPS in Android (9) Pie?

    6 answers







java android json httpurlconnection






share|improve this question













share|improve this question











share|improve this question




share|improve this question










asked Mar 27 at 21:20









user3566569user3566569

441 silver badge7 bronze badges




441 silver badge7 bronze badges





marked as duplicate by Michał Ziober, tir38, gdlmx, Matteo Baldi, Mạnh Quyết Nguyễn Mar 28 at 10:22


This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.











marked as duplicate by Michał Ziober, tir38, gdlmx, Matteo Baldi, Mạnh Quyết Nguyễn Mar 28 at 10:22


This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.









marked as duplicate by Michał Ziober, tir38, gdlmx, Matteo Baldi, Mạnh Quyết Nguyễn Mar 28 at 10:22


This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.














  • How is this "not working"? Crash? Unexpected behavior?

    – tir38
    Mar 28 at 2:21











  • As I wrote it stops on OutputStream os = urlConnection.getOutputStream();. That part is not executed and nothing happens, app doesn't crash, just that part is not executed.

    – user3566569
    Mar 28 at 13:09

















  • How is this "not working"? Crash? Unexpected behavior?

    – tir38
    Mar 28 at 2:21











  • As I wrote it stops on OutputStream os = urlConnection.getOutputStream();. That part is not executed and nothing happens, app doesn't crash, just that part is not executed.

    – user3566569
    Mar 28 at 13:09
















How is this "not working"? Crash? Unexpected behavior?

– tir38
Mar 28 at 2:21





How is this "not working"? Crash? Unexpected behavior?

– tir38
Mar 28 at 2:21













As I wrote it stops on OutputStream os = urlConnection.getOutputStream();. That part is not executed and nothing happens, app doesn't crash, just that part is not executed.

– user3566569
Mar 28 at 13:09





As I wrote it stops on OutputStream os = urlConnection.getOutputStream();. That part is not executed and nothing happens, app doesn't crash, just that part is not executed.

– user3566569
Mar 28 at 13:09












2 Answers
2






active

oldest

votes


















1















Try this add Manifest.xml



cleartextTrafficPermitted="true"


it look like this
How to allow all Network connection types HTTP and HTTPS in Android (9) Pie?






share|improve this answer



























  • Thank you, I added android:usesCleartextTraffic="true" in application tag inside AndroidManifest.xml and it works!

    – user3566569
    Mar 27 at 22:04


















0















This is because of Apache HTTP client depreciation ,
So add the below line in
tag.



<uses-library android:name="org.apache.http.legacy" android:required="false"/>





share|improve this answer

























  • I tried to add that tag and it didn't worked. Solution by Hasan Kucuk to add cleartextTrafficPermitted="true" worked.

    – user3566569
    Mar 27 at 22:20



















2 Answers
2






active

oldest

votes








2 Answers
2






active

oldest

votes









active

oldest

votes






active

oldest

votes









1















Try this add Manifest.xml



cleartextTrafficPermitted="true"


it look like this
How to allow all Network connection types HTTP and HTTPS in Android (9) Pie?






share|improve this answer



























  • Thank you, I added android:usesCleartextTraffic="true" in application tag inside AndroidManifest.xml and it works!

    – user3566569
    Mar 27 at 22:04















1















Try this add Manifest.xml



cleartextTrafficPermitted="true"


it look like this
How to allow all Network connection types HTTP and HTTPS in Android (9) Pie?






share|improve this answer



























  • Thank you, I added android:usesCleartextTraffic="true" in application tag inside AndroidManifest.xml and it works!

    – user3566569
    Mar 27 at 22:04













1














1










1









Try this add Manifest.xml



cleartextTrafficPermitted="true"


it look like this
How to allow all Network connection types HTTP and HTTPS in Android (9) Pie?






share|improve this answer















Try this add Manifest.xml



cleartextTrafficPermitted="true"


it look like this
How to allow all Network connection types HTTP and HTTPS in Android (9) Pie?







share|improve this answer














share|improve this answer



share|improve this answer








edited Jul 5 at 11:52

























answered Mar 27 at 21:43









Hasan KucukHasan Kucuk

5171 gold badge4 silver badges20 bronze badges




5171 gold badge4 silver badges20 bronze badges















  • Thank you, I added android:usesCleartextTraffic="true" in application tag inside AndroidManifest.xml and it works!

    – user3566569
    Mar 27 at 22:04

















  • Thank you, I added android:usesCleartextTraffic="true" in application tag inside AndroidManifest.xml and it works!

    – user3566569
    Mar 27 at 22:04
















Thank you, I added android:usesCleartextTraffic="true" in application tag inside AndroidManifest.xml and it works!

– user3566569
Mar 27 at 22:04





Thank you, I added android:usesCleartextTraffic="true" in application tag inside AndroidManifest.xml and it works!

– user3566569
Mar 27 at 22:04













0















This is because of Apache HTTP client depreciation ,
So add the below line in
tag.



<uses-library android:name="org.apache.http.legacy" android:required="false"/>





share|improve this answer

























  • I tried to add that tag and it didn't worked. Solution by Hasan Kucuk to add cleartextTrafficPermitted="true" worked.

    – user3566569
    Mar 27 at 22:20















0















This is because of Apache HTTP client depreciation ,
So add the below line in
tag.



<uses-library android:name="org.apache.http.legacy" android:required="false"/>





share|improve this answer

























  • I tried to add that tag and it didn't worked. Solution by Hasan Kucuk to add cleartextTrafficPermitted="true" worked.

    – user3566569
    Mar 27 at 22:20













0














0










0









This is because of Apache HTTP client depreciation ,
So add the below line in
tag.



<uses-library android:name="org.apache.http.legacy" android:required="false"/>





share|improve this answer













This is because of Apache HTTP client depreciation ,
So add the below line in
tag.



<uses-library android:name="org.apache.http.legacy" android:required="false"/>






share|improve this answer












share|improve this answer



share|improve this answer










answered Mar 27 at 22:15









Saurav KumarSaurav Kumar

1367 bronze badges




1367 bronze badges















  • I tried to add that tag and it didn't worked. Solution by Hasan Kucuk to add cleartextTrafficPermitted="true" worked.

    – user3566569
    Mar 27 at 22:20

















  • I tried to add that tag and it didn't worked. Solution by Hasan Kucuk to add cleartextTrafficPermitted="true" worked.

    – user3566569
    Mar 27 at 22:20
















I tried to add that tag and it didn't worked. Solution by Hasan Kucuk to add cleartextTrafficPermitted="true" worked.

– user3566569
Mar 27 at 22:20





I tried to add that tag and it didn't worked. Solution by Hasan Kucuk to add cleartextTrafficPermitted="true" worked.

– user3566569
Mar 27 at 22:20



Popular posts from this blog

Kamusi Yaliyomo Aina za kamusi | Muundo wa kamusi | Faida za kamusi | Dhima ya picha katika kamusi | Marejeo | Tazama pia | Viungo vya nje | UrambazajiKuhusu kamusiGo-SwahiliWiki-KamusiKamusi ya Kiswahili na Kiingerezakuihariri na kuongeza habari

Swift 4 - func physicsWorld not invoked on collision? The Next CEO of Stack OverflowHow to call Objective-C code from Swift#ifdef replacement in the Swift language@selector() in Swift?#pragma mark in Swift?Swift for loop: for index, element in array?dispatch_after - GCD in Swift?Swift Beta performance: sorting arraysSplit a String into an array in Swift?The use of Swift 3 @objc inference in Swift 4 mode is deprecated?How to optimize UITableViewCell, because my UITableView lags

Access current req object everywhere in Node.js ExpressWhy are global variables considered bad practice? (node.js)Using req & res across functionsHow do I get the path to the current script with Node.js?What is Node.js' Connect, Express and “middleware”?Node.js w/ express error handling in callbackHow to access the GET parameters after “?” in Express?Modify Node.js req object parametersAccess “app” variable inside of ExpressJS/ConnectJS middleware?Node.js Express app - request objectAngular Http Module considered middleware?Session variables in ExpressJSAdd properties to the req object in expressjs with Typescript