【问题标题】:Apex Callout HTTP Version not supported不支持 Apex 标注 HTTP 版本
【发布时间】:2018-04-05 07:49:53
【问题描述】:

我正在努力从 sfdc 中删除来自亚马逊的文件。

当我通过错误将请求发送到 Amazon It 时,我已经为它编写了代码:-

System.HttpResponse[Status=HTTP 版本不支持,StatusCode=505]

请帮我解决这个问题

我怎样才能克服这个错误来传递正确的请求?

代码:

Datetime expire = system.now().addDays(1);
String dateString = expire.formatGmt('yyyy-MM-dd')+'T'+ expire.formatGmt('HH:mm:ss')+'.'+expire.formatGMT('SSS')+'Z';
String stringToSign =   'DELETE\n' +
                        '\n' +
                        '\n' +
                        dateString + '\n' +
                        ('https://s3.amazonaws.com/'+awsKeySet[0].Name__c+'/'+fname).replaceAll(' ', '');

stringToSign = stringToSign.replaceAll(' ', '%20');
System.debug('FINDME::stringToSign - ' + stringToSign);
Blob mac = Crypto.generateMac('HMacSHA1',Blob.valueOf(stringToSign), Blob.valueOf(+awsKeySet[0].AWS_Secret_Key__c));
stringToSign = EncodingUtil.base64Encode(mac);

//String encoded = EncodingUtil.urlEncode(stringToSign, 'UTF-8');
HttpRequest con = new HttpRequest();
con.setHeader('Authorization',+awsKeySet[0].AWS_AccessKey_Id__c+':' + stringToSign);
con.setEndPoint('https://s3.amazonaws.com/'+awsKeySet[0].Name__c+'/'+'Temporary/'+fname);
con.setHeader('Host',+awsKeySet[0].Name__c+'.s3.amazonaws.com');
//con.setHeader('Date', dateString);
con.setMethod('DELETE');
Http http = new Http();
HTTPResponse res = http.send(con);
System.debug('RES.GETBODY: ' + res.getBody() + ' RES.GETSTATUS: ' + res.getStatus() + ' CON.GETENDPT: ' + con.getEndPoint());

【问题讨论】:

    标签: http salesforce apex


    【解决方案1】:

    此类问题通常由 HTTP 请求中的无效 URL 引起,如 Salesforce 成功社区中的 post 和 Salesforce StackExchange 中的 post 所示。这行是我要开始的地方:

    con.setEndPoint('https://s3.amazonaws.com/'+awsKeySet[0].Name__c+'/'+'Temporary/'+fname);
    

    存在对 sobject 字段 awsKeySet[0].Name__c 和变量 fname 的引用,您可以将它们解析为 URL 字符串。

    您确定其中任何一个的基础值中都没有空格或未转义字符吗?

    【讨论】:

      猜你喜欢
      • 2015-02-13
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2019-03-10
      • 1970-01-01
      • 2011-02-14
      • 2011-12-05
      • 2018-09-11
      相关资源
      最近更新 更多