第七色在线视频,2021少妇久久久久久久久久,亚洲欧洲精品成人久久av18,亚洲国产精品特色大片观看完整版,孙宇晨将参加特朗普的晚宴

為了賬號安全,請及時綁定郵箱和手機(jī)立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

HttpURLConnection with JSON on Android 9, API 28

HttpURLConnection with JSON on Android 9, API 28

溫溫醬 2022-09-07 21:46:44
我正在嘗試在Android 9,API 28中使用HttpURLConnection。它適用于Android 8.0.0,API 26,但不適用于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();            ...我試圖使用以查看哪些代碼未執(zhí)行,我看到它停止在Log.dOutputStream os = urlConnection.getOutputStream();你知道問題出在哪里嗎?
查看完整描述

2 回答

?
慕尼黑8549860

TA貢獻(xiàn)1818條經(jīng)驗 獲得超11個贊

試試這個添加Manifest.xml

cleartextTrafficPermitted="true"

它看起來像這樣 如何允許在Android(9)Pie中的所有網(wǎng)絡(luò)連接類型HTTP和HTTPS?


查看完整回答
反對 回復(fù) 2022-09-07
?
汪汪一只貓

TA貢獻(xiàn)1898條經(jīng)驗 獲得超8個贊

這是因為Apache HTTP客戶端的折舊,所以在標(biāo)簽中添加下面一行。

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


查看完整回答
反對 回復(fù) 2022-09-07
  • 2 回答
  • 0 關(guān)注
  • 91 瀏覽
慕課專欄
更多

添加回答

舉報

0/150
提交
取消
微信客服

購課補(bǔ)貼
聯(lián)系客服咨詢優(yōu)惠詳情

幫助反饋 APP下載

慕課網(wǎng)APP
您的移動學(xué)習(xí)伙伴

公眾號

掃描二維碼
關(guān)注慕課網(wǎng)微信公眾號