向Photoshop API发出了第一个请求
curl用法:
curl --request GET \
--url https://image.adobe.io/pie/psdService/hello \
--header "Authorization: Bearer <YOUR_ACCESS_TOKEN>" \
--header "x-api-key: <YOUR_CLIENT_ID>"
注意:您的令牌将每24小时过期,并且需要在过期后进行刷新。有关以编程方式检索令牌的更多信息,请参见
c++ 代码:
#include <iostream>
#include <curl/curl.h>
using namespace std;
/* 不考虑任何异常的情况, 简单的get请求 */
/***
* buffer 接收数据所在的缓冲区
* size 要读取的字节数
* count 读写size长度的数据count次
* response 用户自定义文件指针
*/
size_t getUrlResponse(char* buffer, size_t size, size_t count, string* response) {
size_t recv_size = size * count;
response->clear();
response->append(buffer);
return recv_size;
}
string get(const string& url) {
// 请求数据
string response;
// easy handle声明
CURL *handle;
// 初始化handle
handle = curl_easy_init();
// 设置url
curl_easy_setopt(handle, CURLOPT_URL, url.c_str());
//设置curl的请求头
struct curl_slist* header_list = NULL;
header_list = curl_slist_append(header_list, "Authorization:Bearer eyJhbGciOiJSUzI1NiIsIng1dSI6Imltc19uYTEta2V5LTEuY2VyIn0.eyJpZCI6IjE2MTk1Nzc1NjgxNDRfMDUzZjg4NzEtNzNkYS00ZGUxLWE4ZDAtY2E3MjBiMGYwZDlmX3VlMSIsImNsaWVudF9pZCI6ImUyMDk2MTc3ZTEzZjRhZDg5YzliZGE0ODliNzgyNGUxIiwidXNlcl9pZCI6IjUwODc3NjgxNjA4Njg2M0EwQTQ5NUM3MUB0ZWNoYWNjdC5hZG9iZS5jb20iLCJ0eXBlIjoiYWNjZXNzX3Rva2VuIiwiYXMiOiJpbXMtbmExIiwiYWFfaWQiOiI1MDg3NzY4MTYwODY4NjNBMEE0OTVDNzFAdGVjaGFjY3QuYWRvYmUuY29tIiwiZmciOiJWTVFCN1RPNUZMUDVQSE1HU01aTFZIUUFKST09PT09PSIsIm1vaSI6IjNlM2FjZWMxIiwiZXhwaXJlc19pbiI6Ijg2NDAwMDAwIiwiY3JlYXRlZF9hdCI6IjE2MTk1Nzc1NjgxNDQiLCJzY29wZSI6Im9wZW5pZCxBZG9iZUlELHJlYWRfb3JnYW5pemF0aW9ucyJ9.l1QoRHqw3FiwOp4_Z-51IlIA3M4izDAMd1Cpixb3KcbkM9s1ujXYerIgZ0_jNrt9NW7qifIMASF0F-X5BIIVdWMRVqW3AwO6Gp2FNndi8X6VXben-iq5BOPt6JA06rlFbv9FXFOzsjDCyFYi9jPqqnFOcov_N3nKcVeVMiSIXEY7Ik2BEkCTCWO7c_VjrgRS3PGSNXfVQlIQxqtRZlzrwRgJTtDCNzO8gXXfsLBXsvTUXOJ7kxQ36snnCRsfXuldYYloiJouQAYH1biibokXaIzPpbRAr0LWRnXS7Ua2YuPuTovsTheltkZQA92JEijhiiy2GA2qmZYBYD97-rbaYg");
header_list = curl_slist_append(header_list, "x-api-key:e2096177e13f4ad89c9bda489b7824e1");
curl_easy_setopt(handle, CURLOPT_HTTPHEADER, header_list);
//curl_easy_setopt(handle, CURLOPT_HTTPGET, NULL);
//设置ssl验证
curl_easy_setopt(handle, CURLOPT_SSL_VERIFYPEER, false);
curl_easy_setopt(handle, CURLOPT_SSL_VERIFYHOST, false);
// 注册回调函数
curl_easy_setopt(handle, CURLOPT_WRITEFUNCTION, &getUrlResponse);
// 获取信息
curl_easy_setopt(handle, CURLOPT_WRITEDATA, &response);
// 执行请求
curl_easy_perform(handle);
// 释放
curl_easy_cleanup(handle);
return response;
}
int main() {
// 使用前初始化libcurl, 只需初始化一次
curl_global_init(CURL_GLOBAL_DEFAULT);
// 执行请求
cout << get("https://image.adobe.io/pie/psdService/hello");
// 释放libcurl相关资源
curl_global_cleanup();
return 0;
}