亚洲在线久爱草,狠狠天天香蕉网,天天搞日日干久草,伊人亚洲日本欧美

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

使用HttpURLConnection進行get請求,返回狀態碼403,網上設置代理的方式均已試過無效,求解

使用HttpURLConnection進行get請求,返回狀態碼403,網上設置代理的方式均已試過無效,求解

白豬掌柜的 2019-03-01 10:47:44
public static String sendGet(String url){ String message = null; try { URL urlGet = new URL(url); HttpURLConnection http = (HttpURLConnection) urlGet.openConnection(); //必須是get方式請求 http.setRequestMethod("GET"); http.setRequestProperty("Content-Type","application/x-www-form-urlencoded"); http.setRequestProperty("Cookie", "dsdsd"); http.setRequestProperty("Referer", url); http.setRequestProperty("User-Agent", "Mozilla/4.0 (compatible; MSIE 8.0; Windows NT 5.1; Trident/4.0; CIBA)"); http.setDoOutput(true); http.setDoInput(true); System.setProperty("sun.net.client.defaultConnectTimeout", "30000");//連接超時30秒 System.setProperty("sun.net.client.defaultReadTimeout", "30000"); //讀取超時30秒 http.connect(); InputStream is =http.getInputStream(); int size =is.available(); byte[] jsonBytes =new byte[size]; is.read(jsonBytes); message=new String(jsonBytes,"UTF-8"); System.out.println("getMessage = "+message); } catch (Exception e) { e.printStackTrace(); } return message; }
查看完整描述

3 回答

?
長風秋雁

TA貢獻1757條經驗 獲得超7個贊

沒下文了啊,

查看完整回答
反對 回復 2019-03-01
  • 3 回答
  • 0 關注
  • 1081 瀏覽
慕課專欄
更多

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯系客服咨詢優惠詳情

幫助反饋 APP下載

慕課網APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網微信公眾號