Mryqu's Notes


  • 首页

  • 搜索
close

[C++] 调试libcurl程序

时间: 2016-12-25   |   分类: C++     |   阅读: 30 字 ~1分钟

最近在调试通过libcurl发送GoogleSheets API POST请求时,增加了一点经验,特此总结。

GoogleSheets API 请求

POST /v4/spreadsheets?access_token={YOUR_ACCESSTOKEN}&fields=spreadsheetId HTTP/1.1
Host: sheets.googleapis.com
Content-Type: application/json;charset=UTF-8
Accept: application/json
Cache-Control: no-cache

{"properties":{"title":"newhaha"},"sheets":[{"properties":{"title":"Sheet1"}}]}

libcurl调试

当GoogleSheets API 请求失败时,仅能获得返回的状态码和消息。感觉没有更多信息可以研究!后来通过CURLOPT_VERBOSE和CURLOPT_DEBUGFUNCTION获得了更多调试信息。

使用CURLOPT_VERBOSE

curl_easy_setopt(m_curl, CURLOPT_VERBOSE, 1L);

libcurl: CURLOPT_VERBOSE这样就可以看到请求报头、响应报头和消息体了。

使用CURLOPT_DEBUGFUNCTION

使用libcurl API指南中CURLOPT_DEBUGFUNCTION示例代码即可。libcurl: CURLOPT_DEBUGFUNCTION这样就可以看到完整的请求和响应内容了。

标题:[C++] 调试libcurl程序
作者:mryqu
声明: 本博客所有文章除特别声明外,均采用 CC BY-NC-SA 3.0 CN 许可协议。转载请注明出处!

#C++# #libcurl# #debug# #dump#
[C++] 将JSON转成字符串
[OpenUI5] jQuery.sap.formatMessage的一点注意事项
  • 文章目录
  • 站点概览

Programmer & Architect

662 日志
27 分类
1472 标签
GitHub Twitter FB Page
    • GoogleSheets API 请求
    • libcurl调试
© 2009 - 2023 Mryqu's Notes
Powered by - Hugo v0.120.4
Theme by - NexT
0%