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

為了賬號(hào)安全,請(qǐng)及時(shí)綁定郵箱和手機(jī)立即綁定
已解決430363個(gè)問題,去搜搜看,總會(huì)有你想問的

HttpUrlConnection中url寫http不行,使用https可以

HttpUrlConnection中url寫http不行,使用https可以

一條小咸魚 2017-06-27 17:30:56
求解?使用http沒有返回。訪問的是http://www.baidu.com,使用GET方法。package?com.example.sty.httpurlconnectiontest; import?android.os.Bundle; import?android.os.Handler; import?android.os.Message; import?android.support.v7.app.AppCompatActivity; import?android.view.View; import?android.widget.Button; import?android.widget.TextView; import?java.io.BufferedReader; import?java.io.IOException; import?java.io.InputStream; import?java.io.InputStreamReader; import?java.net.HttpURLConnection; import?java.net.URL; public?class?MainActivity?extends?AppCompatActivity?{ ????private?static?final?int?SHOW_RESPONSE?=?0; ????private?Button?mButton; ????private?Handler?handler?=?new?Handler()?{ ????????@Override ????????public?void?handleMessage(Message?msg)?{ ????????????switch?(msg.what)?{ ????????????????case?SHOW_RESPONSE: ????????????????????mResponseText.setText((String)?msg.obj); ????????????????????break; ????????????????default: ????????????????????break; ????????????} ????????} ????}; ????private?TextView?mResponseText; ????@Override ????protected?void?onCreate(Bundle?savedInstanceState)?{ ????????super.onCreate(savedInstanceState); ????????setContentView(R.layout.activity_main); ????????mButton?=?(Button)?findViewById(R.id.btn_send_request); ????????mResponseText?=?(TextView)?findViewById(R.id.tv_response); ????????mButton.setOnClickListener(new?View.OnClickListener()?{ ????????????@Override ????????????public?void?onClick(View?view)?{ ????????????????sendRequestWithUrlConnection(); ????????????} ????????}); ????} ????private?void?sendRequestWithUrlConnection()?{ ????????new?Thread(new?Runnable()?{ ????????????@Override ????????????public?void?run()?{ ????????????????HttpURLConnection?connection?=?null; ????????????????try?{ ????????????????????URL?url?=?new?URL("http://www.baidu.com"); ????????????????????connection?=?(HttpURLConnection)?url.openConnection(); ????????????????????connection.setRequestMethod("GET"); ????????????????????connection.setConnectTimeout(5000); ????????????????????connection.setReadTimeout(5000); ????????????????????InputStream?inputStream?=?connection.getInputStream(); ????????????????????StringBuilder?response?=?new?StringBuilder(); ????????????????????BufferedReader?bufferedReader?=?new?BufferedReader(new?InputStreamReader(inputStream)); ????????????????????String?line; ????????????????????while?((line?=?bufferedReader.readLine())?!=?null)?{ ????????????????????????response.append(line); ????????????????????} ????????????????????Message?message?=?new?Message(); ????????????????????message.what?=?SHOW_RESPONSE; ????????????????????message.obj?=?response.toString(); ????????????????????handler.sendMessage(message); ????????????????}?catch?(IOException?e)?{ ????????????????????e.printStackTrace(); ????????????????}?finally?{ ????????????????????if?(connection?!=?null)?{ ????????????????????????connection.disconnect(); ????????????????????} ????????????????} ????????????} ????????}).start(); ????} }
查看完整描述

1 回答

?
蜂之谷

TA貢獻(xiàn)564條經(jīng)驗(yàn) 獲得超863個(gè)贊

百度就是 https啊 不是http

查看完整回答
反對(duì) 回復(fù) 2017-06-27
  • 1 回答
  • 0 關(guān)注
  • 3274 瀏覽

添加回答

舉報(bào)

0/150
提交
取消
微信客服

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

幫助反饋 APP下載

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

公眾號(hào)

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