首页 黄金价格 黄金价格示例代码 黄金价格[C++]
  • 示例代码

本代码示例是基于C 的六派数据接口进行数据请求  API服务请求的代码示例,使用前你需要:

①:通过https://www.6api.net/api/gold/ 申请API服务

以下是完整代码示例:

//post请求
#include <iostream>
//引入第三方库libcurl(需要配置相应环境)
#include <curl/curl.h>

int main(int argc, const char * argv[]) { 
  CURL *curl; 
  CURLcode res; 
  curl_global_init(CURL_GLOBAL_DEFAULT); 
  curl = curl_easy_init(); 
  if(curl) { 
      curl_easy_setopt(curl, CURLOPT_URL, "http://open.liupai.net/gold/shgold"); 
      curl_easy_setopt(curl, CURLOPT_POSTFIELDS, "appkey=yourappsecret&goldid=参数1"); 
      res = curl_easy_perform(curl); 
      std::cout << res << std::endl; 
      curl_easy_cleanup(curl);
  }
  //清空环境
  curl_global_cleanup();
  return 0;
}