国产 无码 综合区,色欲AV无码国产永久播放,无码天堂亚洲国产AV,国产日韩欧美女同一区二区

Android 網(wǎng)絡編程-網(wǎng)絡請求

這篇具有很好參考價值的文章主要介紹了Android 網(wǎng)絡編程-網(wǎng)絡請求。希望對大家有所幫助。如果存在錯誤或未考慮完全的地方,請大家不吝賜教,您也可以點擊"舉報違法"按鈕提交疑問。

Android 網(wǎng)絡編程-網(wǎng)絡請求

本文介紹一下Android 網(wǎng)絡請求,開發(fā)了簡單demo,適合Android入門人員學習。

為啥要寫這個??給應屆生看的。。。

一、主要內容

1、開發(fā)網(wǎng)絡請求前的基本準備
2、普通網(wǎng)絡請求代碼
3、使用OkHttp網(wǎng)絡框架請求網(wǎng)絡代碼
4、使用Retrofit網(wǎng)絡框架請求網(wǎng)絡代碼
5、使用WebView顯示對應網(wǎng)址的網(wǎng)頁
6、應用demo的相關代碼和apk

二、開發(fā)網(wǎng)絡請求前的基本準備

1、查看需要請求的網(wǎng)址是否有效

(1)通過網(wǎng)頁在線驗證

能驗證get請求和簡單的post 請求,比如只設置幾個參數(shù)的post請求
在線get/post請求測試(里面還有一系列工具):
http://www.jsons.cn/httpurl/
http://coolaf.com/

//可以簡單模擬 get/post返回的數(shù)據(jù)
https://v7.apipost.cn/#/apis/design

(2)使用專用window網(wǎng)咯請求工具

① PostMan
② Apifox (國內自研,PostMan加強版,支持網(wǎng)頁和桌面工具)
https://apifox.com/#pricing

(3)編寫app代碼驗證

一般用于驗證文件上傳的情況,
也可以用windows 工具進行驗證,Apifox 也是支持文件上傳的。

2、學會把服務器的json數(shù)據(jù)轉換成Bean對象

在線轉換Json格式轉換JAVA實體Bean類:
http://www.jsons.cn/json2java/

作用?
把字符串的數(shù)據(jù)賦值到對象,使用的時候直接使用 Object.getXXX 獲取返回的某個信息。

也可以使用Android Studio 插件:GsonFormat

3、具體效果測試

get請求測試,可以找網(wǎng)上天氣網(wǎng)址的api或者笑話類的api網(wǎng)址;
post請求測試,可以找地圖類的api(百度地圖),或者語音類的api網(wǎng)址(訊飛)。

簡單測試的網(wǎng)址:
天氣api:

提供天氣,氣象查詢:https://www.yiketianqi.com/index/doc
get請求網(wǎng)址;
https://v0.yiketianqi.com/api?unescape=1&version=v61&appid=28392918&appsecret=No9zfo8f&adcode=440307000000

apipost調試網(wǎng)址

提供get/post簡單調試功能:https://v7.apipost.cn/#/apis/design
注冊登陸后,看起來是可以設計返回的數(shù)據(jù)的,估計是操作要麻煩一點,有需要的可以自己研究。

post請求網(wǎng)址:
https://demo-api.apipost.cn/api/demo/login
mobile=18289454846&ver_code=123456

(1)get請求,在瀏覽器窗口欄請求的顯示

Android 網(wǎng)絡編程-網(wǎng)絡請求,android,網(wǎng)絡框架,android,網(wǎng)絡

(2)get請求在在線請求網(wǎng)址的顯示

Android 網(wǎng)絡編程-網(wǎng)絡請求,android,網(wǎng)絡框架,android,網(wǎng)絡

(3)post請求在在線請求的的網(wǎng)址顯示

post 請求在瀏覽器輸入行直接是無法請求到數(shù)據(jù)的,只能使用專業(yè)的網(wǎng)址或者工具 獲取post請求的數(shù)據(jù)。

Android 網(wǎng)絡編程-網(wǎng)絡請求,android,網(wǎng)絡框架,android,網(wǎng)絡

(4)json數(shù)據(jù)在線轉換成Bean對象

Android 網(wǎng)絡編程-網(wǎng)絡請求,android,網(wǎng)絡框架,android,網(wǎng)絡

應用app效果顯示;

主界面:
Android 網(wǎng)絡編程-網(wǎng)絡請求,android,網(wǎng)絡框架,android,網(wǎng)絡

普通網(wǎng)絡請求:

Android 網(wǎng)絡編程-網(wǎng)絡請求,android,網(wǎng)絡框架,android,網(wǎng)絡

OkHttp網(wǎng)絡請求:
Android 網(wǎng)絡編程-網(wǎng)絡請求,android,網(wǎng)絡框架,android,網(wǎng)絡

retrofit網(wǎng)絡請求:
Android 網(wǎng)絡編程-網(wǎng)絡請求,android,網(wǎng)絡框架,android,網(wǎng)絡
為啥這里TextView顯示的不對,大家可以在代碼里面看看。

WebView界面:
Android 網(wǎng)絡編程-網(wǎng)絡請求,android,網(wǎng)絡框架,android,網(wǎng)絡

應用demo里面顯示了很多WebView界面,這里只展示其中一個。

代碼資源下載地址:

https://download.csdn.net/download/wenzhi20102321/88215651

三、代碼介紹

1、普通網(wǎng)絡請求

網(wǎng)絡請求一定要在子線程執(zhí)行,否則會報錯。
數(shù)據(jù)返回后要顯示在界面上要切換回主線程。

(1)get網(wǎng)絡請求
    //get方法請求網(wǎng)絡
    public void getNetwork(View view) {
        GET_UTL = et_url_get.getText().toString();
        LogUtil.debugInform("GET_UTL = " + GET_UTL);
        //創(chuàng)建線程,請求網(wǎng)絡
        new Thread(new Runnable() {
            @Override
            public void run() {
                // 創(chuàng)建一個URL對象
                URL url = null;
                try {
                    url = new URL(GET_UTL);

                    // 創(chuàng)建一個HttpURLConnection對象,并設置請求方法為GET
                    HttpURLConnection connection = null;
                    connection = (HttpURLConnection) url.openConnection();
                    connection.setRequestMethod("GET");
                    connection.setConnectTimeout(5000);
                    // 獲取服務器響應的狀態(tài)碼
                    int responseCode = 0;
                    responseCode = connection.getResponseCode();
                    if (responseCode == HttpURLConnection.HTTP_OK) {
                        // 讀取服務器響應的數(shù)據(jù)
                        BufferedReader reader = new BufferedReader(new InputStreamReader(connection.getInputStream()));
                        StringBuilder response = new StringBuilder();
                        String line;
                        while ((line = reader.readLine()) != null) {
                            response.append(line); //把讀取的數(shù)據(jù)不斷放入response對象中
                        }
                        reader.close();
                        // 在UI線程中更新UI  runOnUiThread
                         String responseData = response.toString();
                

                    }


                } catch (Exception e) {
                    e.printStackTrace();
                    LogUtil.error("", e);
                }


            }
        }).start();

    }

(2)Post網(wǎng)絡請求

  //post方法請求王網(wǎng)絡
    public void postNetwork(View view) {
       
        //創(chuàng)建線程,請求網(wǎng)絡
        new Thread(new Runnable() {
            @Override
            public void run() {
                // 創(chuàng)建一個URL對象
                URL url = null;
                try {
                    url = new URL(POST_UTL);

                    // 創(chuàng)建一個HttpURLConnection對象,并設置請求方法為GET
                    HttpURLConnection connection = null;
                    connection = (HttpURLConnection) url.openConnection();
                    connection.setConnectTimeout(5000);

                    //------------------------------ 區(qū)別和Get方法 ,Start
                    connection.setRequestMethod("POST");

                    // 啟用輸出流,以便向服務器發(fā)送數(shù)據(jù)
                    connection.setDoOutput(true);

                    // 創(chuàng)建一個輸出流對象,并將數(shù)據(jù)寫入輸出流
                    OutputStream outputStream = connection.getOutputStream();
                    String postData = POST_MESSAGE;
                    outputStream.write(postData.getBytes());
                    outputStream.flush();
                    outputStream.close();
                    //------------------------------ 區(qū)別和Get方法 ,End

                    // 獲取服務器響應的狀態(tài)碼
                    int responseCode = connection.getResponseCode();
                    if (responseCode == HttpURLConnection.HTTP_OK) {
                        // 讀取服務器響應的數(shù)據(jù)
                        BufferedReader reader = new BufferedReader(new InputStreamReader(connection.getInputStream()));
                        StringBuilder response = new StringBuilder();
                        String line;
                        while ((line = reader.readLine()) != null) {
                            response.append(line); //把讀取的數(shù)據(jù)不斷放入response對象中
                        }
                        reader.close();
                        // 在UI線程中更新UI
                         // 處理服務器響應的數(shù)據(jù)
                        String responseData = response.toString();

                    }


                } catch (Exception e) {
                    e.printStackTrace();
                    LogUtil.error("", e);
                }


            }
        }).start();
    }

2、使用OkHttp網(wǎng)絡框架請求網(wǎng)絡

(1)Get網(wǎng)絡請求

    //get方法請求網(wǎng)絡
    public void getNetwork(View view) {
    
        Request request = new Request.Builder()
                .url(GET_UTL)
                .get() //默認為get ,不設置也行
                .build();
        Call call = client.newCall(request);
        //網(wǎng)絡請求的回調
        call.enqueue(new Callback() {
            @Override
            public void onFailure(@NonNull Call call, @NonNull IOException e) {
                Toast.makeText(OkhttpNetworkActivity.this, "請求錯誤:" + e.getMessage(), Toast.LENGTH_LONG).show();
            }

            @Override
            public void onResponse(@NonNull Call call, @NonNull Response response) throws IOException {
                // 處理服務器響應的數(shù)據(jù)
                String responseData = response.body().string();
                LogUtil.debugInform("responseData = " + responseData);
                // TODO: 在這里處理服務器響應的數(shù)據(jù)

            }
        });


    }
(2)Post網(wǎng)絡請求

    //post方法請求王網(wǎng)絡
    public void postNetwork(View view) {
        //創(chuàng)建網(wǎng)絡處理的對象
        OkHttpClient client = new OkHttpClient.Builder()
                .readTimeout(5, TimeUnit.SECONDS)
                .build();

        //mobile=18289454846&ver_code=123456
        //post請求來獲得數(shù)據(jù)
        //創(chuàng)建一個RequestBody,存放重要數(shù)據(jù)的鍵值對
        RequestBody body = new FormBody.Builder()
                .add("mobile", "18289454846")
                .add("ver_code", "123456").build();
        //創(chuàng)建一個請求對象,傳入URL地址和相關數(shù)據(jù)的鍵值對的對象
        Request request = new Request.Builder()
                .url(POST_UTL)
                .post(body).build();

        //創(chuàng)建一個能處理請求數(shù)據(jù)的操作類
        Call call = client.newCall(request);

        //使用異步任務的模式請求數(shù)據(jù)
        call.enqueue(new Callback() {
            @Override
            public void onFailure(Call call, IOException e) {
                LogUtil.error("", e);
            }

            @Override
            public void onResponse(Call call, Response response) throws IOException {

                // 在UI線程中更新UI
                 String responseData = response.body().string();
                 LogUtil.debugInform("result = " + responseData);

            }
        });

    }


3、使用Retrofit網(wǎng)絡框架請求網(wǎng)絡

(1)Get網(wǎng)絡請求

請求示例網(wǎng)址:
https://v0.yiketianqi.com/api?unescape=1&version=v61&appid=28392918&appsecret=No9zfo8f&adcode=440307000000

①創(chuàng)建請求接口對象
package com.example.networkdemo.retrofit;


import com.example.networkdemo.bean.WeatherBean;

import retrofit2.Call;
import retrofit2.http.GET;
import retrofit2.http.Query;

/**
 * Get請求
 * 這里使用get請求的方式請求數(shù)據(jù)
 * 并且到的是字符串數(shù)據(jù)
 */
public interface RetrofitWeatherService {
    //鍵值對的定義和數(shù)據(jù)的返回類型的定義這里是String
    //https://v0.yiketianqi.com/api?unescape=1&version=v61&appid=28392918&appsecret=No9zfo8f&adcode=440307000000
    //這里使用 @Field 是會報錯,是要使用 @Query
    @GET("api")//get請求方式
    Call<WeatherBean> getWeather(@Query("unescape") String unescape, @Query("version") String version,
                                 @Query("appid") String appid, @Query("appsecret") String appsecret, @Query("adcode") String adcode);
}


② 具體的請求代碼

比如在某個Activity寫如下代碼


    //get方法請求網(wǎng)絡
    public void getNetwork(View view) {

        Retrofit retrofit = getGsonRetrofit(GET_UTL);

        RetrofitWeatherService weatherService = retrofit.create(RetrofitWeatherService.class);
        //?unescape=1&version=v61&appid=28392918&appsecret=No9zfo8f&adcode=440307000000"
        Call<WeatherBean> call = weatherService.getWeather("1", "v61", "28392918", "No9zfo8f", "440307000000");
        //轉換成Call,在call對象包含Url的完整地址
        //可以看到這里使用了create的方法,里面?zhèn)魅肓苏埱蠓盏慕涌陬?        //并且后面接的是接口類的方法,方法里面?zhèn)魅險rl地址要的鍵值對的值
        //這時call對象就有完整的Url地址,就可以請求數(shù)據(jù)了
        //使用call對象進行網(wǎng)絡數(shù)據(jù)請求
        call.enqueue(new Callback<WeatherBean>() {
            //網(wǎng)絡數(shù)據(jù)請求成功的回調方法
            @Override
            public void onResponse(Call<WeatherBean> call, Response<WeatherBean> response) {

                runOnUiThread(new Runnable() {
                    @Override
                    public void run() {
                        WeatherBean bean = response.body();
                        tv_info.setText(TimeUtil.getTimeString() + " \n Get請求的數(shù)據(jù):" + bean + "");
                        String air_tips = bean.getAir_tips();
                        String update_time = bean.getUpdate_time();
                        String tem1 = bean.getTem1();
                        String tem2 = bean.getTem2();
                        String tem = bean.getTem();
                        Toast.makeText(RetrofitNetworkActivity.this, "天氣時間:" + update_time
                                + "\n 當前溫度:" + tem + ",溫度變化" + tem2 + "--" + tem1 +
                                "\n 溫馨提示:" + air_tips, Toast.LENGTH_LONG).show();
                    }
                });
            }

            //網(wǎng)絡數(shù)據(jù)請求失敗的回調方法
            @Override
            public void onFailure(Call<WeatherBean> call, Throwable t) {
                tv_info.setText(TimeUtil.getTimeString() + " \n Get 請求的失敗日志:" + t.getMessage() + "");
            }
        });

    }
(2)Post網(wǎng)絡請求

Post請求網(wǎng)址:https://demo-api.apipost.cn/api/demo/login
攜帶信息:mobile=18289454846&ver_code=123456

①創(chuàng)建請求接口對象
package com.example.networkdemo.retrofit;



import com.example.networkdemo.bean.LoginBean;

import retrofit2.Call;
import retrofit2.http.Field;
import retrofit2.http.FormUrlEncoded;
import retrofit2.http.POST;

/**
 * 登陸服務器的請求
 * 這里使用post請求的方式請求數(shù)據(jù)
 * 并且到的是一個自定義的對象數(shù)據(jù)
 */
public interface RetrofitLoginService {
    //https://demo-api.apipost.cn/api/demo/login
    @POST("api/demo/login")//Post請求方式
    @FormUrlEncoded      //鍵值對的定義和數(shù)據(jù)的返回類型的定義這里是String
    Call<LoginBean> login(@Field("mobile") String mobile, @Field("ver_code") String ver_code);
}

② 具體的請求代碼

    //post方法請求王網(wǎng)絡
    public void postNetwork(View view) {
      
        Retrofit retrofit = getGsonRetrofit(POST_UTL); //https://demo-api.apipost.cn/
        RetrofitLoginService loginService = retrofit.create(RetrofitLoginService.class);
        Call<LoginBean> call = loginService.login("18289454846", "123456");
        call.enqueue(new Callback<LoginBean>() {
            @Override
            public void onResponse(Call<LoginBean> call, Response<LoginBean> response) {
                // 在UI線程中更新UI
                runOnUiThread(new Runnable() {
                    @Override
                    public void run() {
                        // 處理服務器響應的數(shù)據(jù)
                        LoginBean loginBean = response.body();
                        LogUtil.debugInform("loginBean = " + loginBean);
                        int code = loginBean.getCode();
                        LoginBean.DataBean data = loginBean.getData();
                        String msg = loginBean.getMsg();
                        Toast.makeText(RetrofitNetworkActivity.this, "登陸信息:" +
                                "\n code = " + code + ", msg = " + msg, Toast.LENGTH_LONG).show();
                        LogUtil.debugInform("data getToken = " + data.getToken());

                        // TODO: 在這里處理服務器響應的數(shù)據(jù)
                        tv_info.setText(TimeUtil.getTimeString() + " \n Post請求的數(shù)據(jù):" + response + "");
                    }
                });
            }

            @Override
            public void onFailure(Call<LoginBean> call, Throwable t) {
                runOnUiThread(new Runnable() {
                    @Override
                    public void run() {
                        tv_info.setText(TimeUtil.getTimeString() + " \n Post請求的失敗日志:" + t.getMessage() + "");
                    }
                });
            }
        });
    }


    //返回一個Gson類型的對象
    public Retrofit getGsonRetrofit(String url) {
        Retrofit retrofit = new Retrofit.Builder().baseUrl(url)
                .addConverterFactory(GsonConverterFactory.create())
                .build();
        return retrofit;
    }


    //返回一個Gson類型的字符串,
    public Retrofit getStringRetrofit(String url) {
        Retrofit retrofit = new Retrofit.Builder().baseUrl(url)
                .addConverterFactory(ScalarsConverterFactory.create())
                .build();
        return retrofit;
    }


4、使用WebView顯示對應網(wǎng)址的網(wǎng)頁

(1)在布局文件寫入控件WebView
   <WebView
        android:id="@+id/web_view"
        android:layout_width="match_parent"
        android:layout_height="match_parent" />

(2) 設置基本參數(shù)

         web_view = findViewById(R.id.web_view);
  
        WebSettings webSettings = web_view.getSettings();
        //如果訪問的頁面中要與Javascript交互,則webview必須設置支持Javascript
        webSettings.setJavaScriptEnabled(true);
        webSettings.setDefaultTextEncodingName("utf-8");//設置編碼格式

        //要顯示的網(wǎng)址:
        web_view.loadUrl(url); //設置網(wǎng)址

這里只是基本代碼,還可以設置跳轉監(jiān)聽,前進后退網(wǎng)頁跳轉等,可以自己調試研究。

三、總結

1、網(wǎng)絡請求是要在子線程內進行

2、不同框架的網(wǎng)絡請求根據(jù)項目具體情況使用

如果頻率很多的使用網(wǎng)絡請求,直接使用原生請求即可,不用使用網(wǎng)絡框架。
如果使用頻率很高,可以使用健全的網(wǎng)絡框架:OkHttp/Retrofit;
OkHttp使用簡單,Retrofit 使用復雜一些,但是和很多其他框架可以結合使用,比如Gson,RxJava等。

3、Android 網(wǎng)絡編程要學習些什么

(1)網(wǎng)絡分層和HTTP協(xié)議基本知識,比如請求報文和響應報文

雖然不一定會用到,但是也是要知道里面的知識點。

(2)Java網(wǎng)絡編程基礎,TCP/UDP 進行連接交互

可以寫demo,一個作為客戶端一個作為服務端,連接后進行通訊交互。

(3)Json數(shù)據(jù)轉Gson對象

網(wǎng)絡上數(shù)據(jù)請求基本都是返回json數(shù)據(jù),使用Gson對象可以直接轉換成對應的對象,使用起來比較方便。

但是也有一些網(wǎng)絡請求返回的數(shù)據(jù)不是json數(shù)據(jù)格式,比如xml格式,或者其他特定格式。
這個就需要自己寫工具類進行解析了。

(4)Android基本網(wǎng)絡請求和基本網(wǎng)絡框架使用

不使用網(wǎng)絡框架請求網(wǎng)絡和使用主流網(wǎng)絡框架請求網(wǎng)絡。

(5)加密算法:數(shù)據(jù)加密和解密

因為網(wǎng)絡數(shù)據(jù)是經(jīng)過加密的,所以必須要經(jīng)過解密才能讀取到正常數(shù)據(jù)。
算法是會使用框架就行了的,具體算法一般人寫不出來!文章來源地址http://www.zghlxwxcb.cn/news/detail-649426.html

到了這里,關于Android 網(wǎng)絡編程-網(wǎng)絡請求的文章就介紹完了。如果您還想了解更多內容,請在右上角搜索TOY模板網(wǎng)以前的文章或繼續(xù)瀏覽下面的相關文章,希望大家以后多多支持TOY模板網(wǎng)!

本文來自互聯(lián)網(wǎng)用戶投稿,該文觀點僅代表作者本人,不代表本站立場。本站僅提供信息存儲空間服務,不擁有所有權,不承擔相關法律責任。如若轉載,請注明出處: 如若內容造成侵權/違法違規(guī)/事實不符,請點擊違法舉報進行投訴反饋,一經(jīng)查實,立即刪除!

領支付寶紅包贊助服務器費用

相關文章

  • C語言網(wǎng)絡編程:實現(xiàn)自己的高性能網(wǎng)絡框架

    C語言網(wǎng)絡編程:實現(xiàn)自己的高性能網(wǎng)絡框架

    一般生產(chǎn)環(huán)境中最耗時的其實是業(yè)務邏輯處理。所以,是不是可以將處理業(yè)務邏輯的代碼給拆出來丟到線程池中去執(zhí)行。 比如像下面這樣: ?我們事先創(chuàng)建好一堆worker線程,主線程accepter拿到一個連接上來的套接字,就從線程池中取出一個線程將這個套接字交給它。這樣,我

    2024年02月10日
    瀏覽(24)
  • ESP8266-Arduino網(wǎng)絡編程實例-HTTPS客戶端數(shù)據(jù)請求

    超文本傳輸協(xié)議安全 (HTTPS) 是 HTTP的安全版本,HTTP 是用于在 Web 瀏覽器和網(wǎng)站之間發(fā)送數(shù)據(jù)的主要協(xié)議。HTTPS 經(jīng)過加密,以提高數(shù)據(jù)傳輸?shù)陌踩浴.斢脩魝鬏斆舾袛?shù)據(jù)(例如通過登錄銀行賬戶、電子郵件服務或健康保險提供商)時,這一點尤其重要。 從技術上來講,HTTPS

    2023年04月08日
    瀏覽(18)
  • Qt 網(wǎng)絡編程之美:探索 URL、HTTP、服務發(fā)現(xiàn)與請求響應

    Qt 網(wǎng)絡編程是使用 Qt 框架進行網(wǎng)絡應用開發(fā)的重要組成部分。Qt 是一個跨平臺的 C++ 應用程序開發(fā)框架,廣泛應用于各種領域,包括桌面應用、移動應用和嵌入式設備。在本文中,我們將探討 Qt 網(wǎng)絡編程的優(yōu)勢,以及本文涉及的主題,包括 URL、HTTP、服務發(fā)現(xiàn)和請求響應等。

    2023年04月23日
    瀏覽(24)
  • Java 網(wǎng)絡編程 —— 客戶端協(xié)議處理框架

    Java 對客戶程序的通信過程進行了抽象,提供了通用的協(xié)議處理框架,該框架封裝了 Socket,主要包括以下類: URL 類:統(tǒng)一資源定位符,表示客戶程序要訪問的遠程資源 URLConnection 類:表示客戶程序與遠程服務器的連接,客戶程序可以從 URLConnection 獲得數(shù)據(jù)輸入流和輸出流

    2024年02月07日
    瀏覽(31)
  • 【Linux網(wǎng)絡編程】高并發(fā)服務器框架 線程池介紹+線程池封裝

    【Linux網(wǎng)絡編程】高并發(fā)服務器框架 線程池介紹+線程池封裝

    前言 一、線程池介紹 ??線程池基本概念 ??線程池組成部分 ??線程池工作原理? 二、線程池代碼封裝 ??main.cpp ??ThreadPool.h ??ThreadPool.cpp ??ChildTask.h? ??ChildTask.cpp ??BaseTask.h ??BaseTask.cpp 三、測試效果 四、總結 ??創(chuàng)建線程池的好處 本文主要學習 Linux內核編程 ,結合

    2024年01月16日
    瀏覽(33)
  • Qt網(wǎng)絡編程post請求,數(shù)據(jù)格式為json或x-www-form-urlencoded

    目錄 Qt網(wǎng)絡編程post請求,數(shù)據(jù)格式為json或x-www-form-urlencoded 一、.H文件 1、.h頭文件 2、.h主代碼 二、.CPP文件 1、主代碼 ?三、響應信息 返回結果(Josn數(shù)據(jù)格式輸出) 四、Post數(shù)據(jù)格式參數(shù)及數(shù)據(jù)類型定義 1、Post:application/x-www-form-urlencoded數(shù)據(jù)類型格式 2、Post:application/json數(shù)據(jù)

    2024年02月07日
    瀏覽(29)
  • Linux 網(wǎng)絡編程學習筆記——十二、高性能 I/O 框架庫 Libevent

    Linux 網(wǎng)絡編程學習筆記——十二、高性能 I/O 框架庫 Libevent

    在處理 I/O 事件、信號和定時事件時,需要考慮如下三個問題: 統(tǒng)一事件源:很明顯,統(tǒng)一處理這三類事件既能使代碼簡單易懂,又能避免一些潛在的邏輯錯誤。 可移植性:不同的操作系統(tǒng)具有不同的 I/O 復用方式,比如 Solaris 的 dev/poll 文件,F(xiàn)reeBSD 的 kqueue 機制,Linux 的

    2023年04月08日
    瀏覽(35)
  • 【雕爺學編程】Arduino智能家居之連接到WiFi網(wǎng)絡并發(fā)送GET請求獲取數(shù)據(jù)

    【雕爺學編程】Arduino智能家居之連接到WiFi網(wǎng)絡并發(fā)送GET請求獲取數(shù)據(jù)

    Arduino是一個開放源碼的電子原型平臺,它可以讓你用簡單的硬件和軟件來創(chuàng)建各種互動的項目。Arduino的核心是一個微控制器板,它可以通過一系列的引腳來連接各種傳感器、執(zhí)行器、顯示器等外部設備。Arduino的編程是基于C/C++語言的,你可以使用Arduino IDE(集成開發(fā)環(huán)境)來

    2024年02月04日
    瀏覽(19)
  • Android 網(wǎng)絡請求方式

    最近需要將Android 項目接入物聯(lián)網(wǎng)公司提供的接口,所以順便給大家分享一下Android中我們常用的網(wǎng)絡請求吧!提醒大家一下,我們遇到接口需求,一定要先在Postman上測試接口是否正確,然后再去項目上寫程序來請求接口;否則,請求出問題,你都不確定是你程序寫的有問題還

    2024年02月07日
    瀏覽(17)
  • Android實現(xiàn)網(wǎng)絡請求方法

    Android實現(xiàn)網(wǎng)絡請求方法

    ? 安卓開發(fā)網(wǎng)絡請求可謂是安卓開發(fā)的靈魂,如果你不會網(wǎng)絡請求,那么你開發(fā)的應用軟件就是一具沒有靈魂的枯骨。 ? 在安卓開發(fā)中進行網(wǎng)絡請求和java中的網(wǎng)絡請求有異曲同工之妙,但是安卓軟件畢竟的安裝在我們手機上的,而平常的應用軟件下載后會要求你給與權限,

    2024年02月10日
    瀏覽(17)

覺得文章有用就打賞一下文章作者

支付寶掃一掃打賞

博客贊助

微信掃一掃打賞

請作者喝杯咖啡吧~博客贊助

支付寶掃一掃領取紅包,優(yōu)惠每天領

二維碼1

領取紅包

二維碼2

領紅包