当前位置: 首页 > news >正文

学网站建设要多长时间健身所网站建设策划书

学网站建设要多长时间,健身所网站建设策划书,渭南市住建设局网站,网站建设 九艾一。由于工作的原因#xff0c;需要对curl做一些封装#xff0c;附加上我们的证书#xff0c;提供给第三个C和jAVA使用。 二。头文件封闭四个函数#xff0c;get#xff0c;post#xff0c;download#xff0c;upload #ifndef CURLHTTP_H #define CURLHTTP_H#include …一。由于工作的原因需要对curl做一些封装附加上我们的证书提供给第三个C和jAVA使用。 二。头文件封闭四个函数getpostdownloadupload #ifndef CURLHTTP_H #define CURLHTTP_H#include iostream #include string #include curl/curl.hclass CurlHttp { public: CurlHttp(); ~CurlHttp();CURLcode get(const std::string url, std::string response); CURLcode post(const std::string url, const std::string data, std::string response); CURLcode download(const std::string url, const std::string savePath); CURLcode upload(const std::string url, const std::string filePath, std::string response); private: CURL* curl;static size_t WriteCallback(void* contents, size_t size, size_t nmemb, std::string* response); void setSSLSettings(); };#endif // CURLHTTP_H三。实现Cpp返回一个CURLcode方便出错时追踪错误 #include CurlHttp.hCurlHttp::CurlHttp() {curl curl_easy_init();if (!curl) {std::cerr Failed to initialize cURL std::endl;} }CurlHttp::~CurlHttp() {if (curl) {curl_easy_cleanup(curl);} }CURLcode CurlHttp::get(const std::string url, std::string response) {CURLcode res CURLE_FAILED_INIT;if (curl) {curl_easy_setopt(curl, CURLOPT_URL, url.c_str());curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION, WriteCallback);curl_easy_setopt(curl, CURLOPT_WRITEDATA, response);setSSLSettings();res curl_easy_perform(curl);if (res ! CURLE_OK) {std::cerr cURL GET request failed: curl_easy_strerror(res) std::endl;}}return res; }CURLcode CurlHttp::post(const std::string url, const std::string data, std::string response) {CURLcode res CURLE_FAILED_INIT;if (curl) {curl_easy_setopt(curl, CURLOPT_URL, url.c_str());curl_easy_setopt(curl, CURLOPT_POSTFIELDS, data.c_str());curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION, WriteCallback);curl_easy_setopt(curl, CURLOPT_WRITEDATA, response);setSSLSettings();// 设置请求头为JSON类型struct curl_slist* headers nullptr;headers curl_slist_append(headers, Content-Type: application/json);curl_easy_setopt(curl, CURLOPT_HTTPHEADER, headers);res curl_easy_perform(curl);if (res ! CURLE_OK) {std::cerr cURL POST request failed: curl_easy_strerror(res) std::endl;}}return res; }CURLcode CurlHttp::download(const std::string url, const std::string savePath) {CURLcode res CURLE_FAILED_INIT;if (curl) {FILE* file fopen(savePath.c_str(), wb);if (file) {curl_easy_setopt(curl, CURLOPT_URL, url.c_str());curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION, NULL);curl_easy_setopt(curl, CURLOPT_WRITEDATA, file);setSSLSettings();res curl_easy_perform(curl);if (res ! CURLE_OK) {std::cerr cURL download failed: curl_easy_strerror(res) std::endl;}fclose(file);} else {std::cerr Failed to open file for writing: savePath std::endl;res CURLE_FAILED_INIT;}}return res; }CURLcode CurlHttp::upload(const std::string url, const std::string filePath, std::string response) {CURLcode res CURLE_FAILED_INIT;if (curl) {FILE* file fopen(filePath.c_str(), rb);if (file) {curl_easy_setopt(curl, CURLOPT_URL, url.c_str());curl_easy_setopt(curl, CURLOPT_UPLOAD, 1L);curl_easy_setopt(curl, CURLOPT_READDATA, file);curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION, WriteCallback);curl_easy_setopt(curl, CURLOPT_WRITEDATA, response);setSSLSettings();res curl_easy_perform(curl);if (res ! CURLE_OK) {std::cerr cURL upload failed: curl_easy_strerror(res) std::endl;}fclose(file);} else {std::cerr Failed to open file for reading: filePath std::endl;res CURLE_FAILED_INIT;}}return res; }size_t CurlHttp::WriteCallback(void* contents, size_t size, size_t nmemb, std::string* response) {size_t total_size size * nmemb;//response-append((char*)contents, total_size);response-append(static_castchar*(contents), totalSize);return total_size; }void CurlHttp::setSSLSettings() {// 设置证书路径curl_easy_setopt(curl, CURLOPT_CAINFO, /path/to/certificate.pem);// 设置私钥路径curl_easy_setopt(curl, CURLOPT_SSLKEY, /path/to/private.key);// 设置私钥密码如果有的话curl_easy_setopt(curl, CURLOPT_KEYPASSWD, password); }四。测试函数 #include iostream #include CurlHttp.hint main() {CurlHttp curlHttp;// 发起 GET 请求std::string url https://api.example.com/data;std::string response;CURLcode res curlHttp.get(url, response);if (res CURLE_OK) {std::cout GET request successful. Response: response std::endl;} else {std::cerr GET request failed. Error: curl_easy_strerror(res) std::endl;}// 发起 POST 请求url https://api.example.com/post;std::string data key1value1key2value2;response.clear();res curlHttp.post(url, data, response);if (res CURLE_OK) {std::cout POST request successful. Response: response std::endl;} else {std::cerr POST request failed. Error: curl_easy_strerror(res) std::endl;}// 下载文件url https://example.com/file.jpg;std::string savePath /path/to/save/file.jpg;res curlHttp.download(url, savePath);if (res CURLE_OK) {std::cout File downloaded successfully and saved at: savePath std::endl;} else {std::cerr File download failed. Error: curl_easy_strerror(res) std::endl;}// 上传文件url https://api.example.com/upload;std::string filePath /path/to/upload/file.txt;response.clear();res curlHttp.upload(url, filePath, response);if (res CURLE_OK) {std::cout File uploaded successfully. Response: response std::endl;} else {std::cerr File upload failed. Error: curl_easy_strerror(res) std::endl;}return 0; }六。创建一个aidl文件 package com.example.yourpackage; // 替换为您的包名interface ICurlHttpService {int get(in String url, out String response);int post(in String url, in String data, out String response);int download(in String url, in String savePath);int upload(in String url, in String filePath, out String response); }
http://www.hkea.cn/news/14307549/

相关文章:

  • 昭通公司做网站wordpress 远程设置
  • 视频网站建设教程网络服务提供者接到权利人
  • 软件开发活动的顺序应该是wordpress主题 SEO优化
  • 个人备案网站名称大全php空间租用
  • 建设银行网站的特点浙江省住建厅证书查询
  • 网站优化排名如何做wordpress mysql权限
  • 怎么做 在线电影网站营销网站优化seo
  • 潍坊百度网站建设网站建设站长相关专业
  • 免费申请空间网站一个完整网页的制作案例
  • 安徽专业建网站怎么做锅炉网站
  • 婚恋网站女代我做彩票dw网页制作登录页面步骤
  • 网站建设竞价托管外包南通做企业网站
  • 做知乎网站要多少钱wordpress密码漏洞’
  • 响应式网站什么意思如何购买企业黄页网站
  • 思行做网站公众号平台网页版
  • 怎么用自己注册的域名做网站免费linux网站空间
  • 东莞做网站能赚钱吗网页建站建设教程
  • 做外贸没有网站可以吗成都网站建设上市
  • 企业网站的优点厦门企业建站模板
  • 邢台网站建设网站wordpress换php7出错
  • 农业展示网站模板下载自己做一个网站需要多少钱
  • 网站建设需求表格中文域名网站标识
  • 宜昌做网站要什么条件wap浏览器是什么意思
  • 怎样直接输入网址打开网站山东各地网站备案
  • 正在备案怎么建网站资源网站自己建设还是发软文
  • 芜湖网站建设优化杭州设计制作网站
  • 网站什么内容wordpress 函数文件
  • 合肥网站建设技术wordpress目录seo
  • 做网络传销网站犯法吗高淳网站建设
  • 中国建设招聘网站甘肃分行郓城县网站建设