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;
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?
java android json httpurlconnection
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.
add a comment |
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?
java android json httpurlconnection
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
add a comment |
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?
java android json httpurlconnection
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
java android json httpurlconnection
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
add a comment |
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
add a comment |
2 Answers
2
active
oldest
votes
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?
Thank you, I added android:usesCleartextTraffic="true" in application tag inside AndroidManifest.xml and it works!
– user3566569
Mar 27 at 22:04
add a comment |
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"/>
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
add a comment |
2 Answers
2
active
oldest
votes
2 Answers
2
active
oldest
votes
active
oldest
votes
active
oldest
votes
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?
Thank you, I added android:usesCleartextTraffic="true" in application tag inside AndroidManifest.xml and it works!
– user3566569
Mar 27 at 22:04
add a comment |
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?
Thank you, I added android:usesCleartextTraffic="true" in application tag inside AndroidManifest.xml and it works!
– user3566569
Mar 27 at 22:04
add a comment |
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?
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?
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
add a comment |
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
add a comment |
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"/>
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
add a comment |
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"/>
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
add a comment |
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"/>
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"/>
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
add a comment |
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
add a comment |
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