Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

Libcurl lesson 11 use and matters needing attention

2025-04-02 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Internet Technology >

Share

Shulou(Shulou.com)06/02 Report--

experience

1) cooperate with Postman to generate sample code quickly.

2) curl_global_init initialization

If curl_global_init is not called to initialize the curl global variable when the curl library function is called, the initialization call will be made in the curl_easy_init function.

3) when requesting data, you should carry the format of the return message, otherwise you will not be able to return valid data

Struct curl_slist * pCurlHeadList = NULL

PCurlHeadList = curl_slist_append (pCurlHeadList, "content-type: application/json")

Curl_easy_setopt (pCurlHandle, CURLOPT_HTTPHEADER, pCurlHeadList)

Currently, when interfacing with the backend of an ASP web page, you must specify the format of the transmitted text

4) the delay of libcurl transmission reaches 1 second

When the length of POST data is greater than 1024 bytes, libcurl will not send the POST request directly, but will execute it in two steps:

Send a request with an Expect: 100-continue field in the header to ask server if it is willing to receive data

When a reply from the 100-continue returned from server is received, the POST request is actually initiated and the data is sent to server.

Solution

Struct curl_slist * pCurlList = NULL

PCurlList = curl_slist_append (pCurlList, "expect:")

Curl_easy_setopt (pCurlHandle, CURLOPT_HTTPHEADER, pCurlList)

5) return error code record analysis

CURLE_COULDNT_CONNECT (7)

The host or agent for connect () failed.

CURLE_GOT_NOTHING (52)

In the case of a successful server connection, but no return from the server, and what is obtained, it is considered an error

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Internet Technology

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report