Android 中HttpURLConnection與HttpClient使用的簡(jiǎn)單實(shí)例
1:HttpHelper.java
public class HttpHelper {
//1:標(biāo)準(zhǔn)的Java接口
public static String getStringFromNet1(String param){
String result="";
try{
URL url=new URL(param);
HttpURLConnection conn=(HttpURLConnection)url.openConnection();
if(conn.getResponseCode()==HttpURLConnection.HTTP_OK){
InputStream is=conn.getInputStream();
byte[]data=new byte[1024];
int len=is.read(data);
result=new String(data,0,len);
is.close();
conn.disconnect();
}
}catch(Exception e){
e.printStackTrace();
}
return result;
}
//2:Apache接口
public static String getStringFromNet2(String param){
String result="";
try{
HttpClient client=new DefaultHttpClient();
HttpGet get=new HttpGet(param);
HttpResponse response=client.execute(get);
if(response.getStatusLine().getStatusCode()==HttpStatus.SC_OK){
result=EntityUtils.toString(response.getEntity());
}
}catch(Exception e){
e.printStackTrace();
}
return result;
}
}
- Android HttpURLConnection下載網(wǎng)絡(luò)圖片設(shè)置系統(tǒng)壁紙
- Android 用HttpURLConnection訪(fǎng)問(wèn)網(wǎng)絡(luò)的方法
- Android基于HttpUrlConnection類(lèi)的文件下載實(shí)例代碼
- Android網(wǎng)絡(luò)技術(shù)HttpURLConnection詳解
- Android程序開(kāi)發(fā)通過(guò)HttpURLConnection上傳文件到服務(wù)器
- Android HttpURLConnection.getResponseCode()錯(cuò)誤解決方法
- Android使用HttpURLConnection實(shí)現(xiàn)網(wǎng)絡(luò)訪(fǎng)問(wèn)流程
相關(guān)文章
Android5.0中多種水波紋效果的實(shí)現(xiàn)代碼
這篇文章主要介紹了Android5.0中多種水波紋效果的實(shí)現(xiàn)代碼,水波紋效果大致上可以分為兩種,一種是有界的,一種無(wú)界,一起跟隨小編過(guò)來(lái)看看吧2018-05-05Flutter 自定義Drawer 滑出位置的大小實(shí)例代碼詳解
這篇文章主要介紹了Flutter 自定義Drawer 滑出位置的大小,本文通過(guò)實(shí)例代碼給大家介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或工作具有一定的參考借鑒價(jià)值,需要的朋友可以參考下2020-04-04Android自定義viewgroup 使用adapter適配數(shù)據(jù)(6)
這篇文章主要為大家詳細(xì)介紹了Android自定義viewgroup,使用adapter適配數(shù)據(jù),具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下2016-12-12Android開(kāi)發(fā)之Sqliteopenhelper用法實(shí)例分析
這篇文章主要介紹了Android開(kāi)發(fā)之Sqliteopenhelper用法,實(shí)例分析了SQLiteOpenHelper類(lèi)操作數(shù)據(jù)庫(kù)的相關(guān)技巧,需要的朋友可以參考下2015-05-05Android RecyclerView 數(shù)據(jù)綁定實(shí)例代碼
本文主要介紹Android RecyclerView 數(shù)據(jù)綁定的資料,這里詳細(xì)說(shuō)明如何實(shí)現(xiàn) Android RecyclerView的數(shù)據(jù)綁定,并附示例代碼,有需要的小伙伴可以參考下2016-09-09Android實(shí)現(xiàn)輸入法彈出時(shí)把布局頂上去和登錄按鈕頂上去的解決方法
這篇文章主要介紹了Android實(shí)現(xiàn)輸入法彈出時(shí)把布局頂上去和登錄按鈕頂上去的解決方法,需要的朋友可以參考下2017-11-11Android模擬器對(duì)應(yīng)的電腦快捷鍵說(shuō)明
Android模擬器對(duì)應(yīng)的電腦快捷鍵說(shuō)明,需要的朋友可以參考一下2013-06-06