curl - 根据我的代码为 APEX 制作卷曲标注
问题描述
我知道之前有人问过这个问题:
但是 Curl 的格式与我的不一样,所以我想知道如何在 Apex 端点编程中转换它?
curl H "Content-Type:application/json" -H "charset:UTF-8" -H "Authorization:Bearer [access token]" -X POST -d '{[body]}' [endpoint]
我的代码:
public static httpResponse callout(String httpMethod, String endpoint, String body){
//Instantiate an httpRequest and set the required attributes
httpRequest req = new httpRequest();
req.setMethod(httpMethod);
req.setEndpoint(endpoint);
//Optional attributes are often required to conform to the 3rd Party Web Service Requirements
req.setHeader('Content-Type', 'application/json; charset=utf-8');
req.setHeader('Authorization','Bearer' + 'xxxxxxxxxxxx[this is the access token]');
req.setBody('taken the body');
//You can adjust the timeout duration (in milliseconds) to deal with slow servers or large payloads
req.setTimeout(120000);
//Use the HTTP Class to send the httpRequest and receive an httpResposne
/*If you are not using an HttpCalloutMock:
if (!test.isRunningTest){
*/
httpResponse res = new http().send(req);
/*If you are not using an HttpCalloutMock:
}
*/
system.debug(res.toString());
system.debug(res.getBody());
return res;
}
我收到了内部错误的错误 500,我不知道为什么。
解决方案
推荐阅读
- java - 将@Transactional 和调用两个或多个表的逻辑放在哪里?
- ios - SwiftUI:如何将 CoreData 与动态过滤器相加?
- xamarin.forms - Xamarin.Forms 每个平台和设备的不同视图
- networking - iptables,两条规则,我正在努力弄清楚我在这里做什么
- r - KNN 用于从新数据中预测类别
- youtube-api - YouTube API - “授权重定向 URI”选项未显示在凭据页面上
- php - 如何使用 Laravel 导入 CSV 以“更新”数据库中的现有记录
- ios - iOS 中的推送通知服务扩展未执行
- go - 如何从其他函数解析切片
- php - 有没有另一种方法来转换多维数组?