简体   繁体   中英

Apex Callout HTTP Version not supported

I am working on deleting the file from the Amazon from sfdc.

I have written the code for it when am sending the request to Amazon It through error:-

System.HttpResponse[Status=HTTP Version not supported, StatusCode=505]

kindly help me to solve this problem

How can I overcome this error to pass correct request?

Code:

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());

This kind of problem typically arises from an invalid URL in the HTTP request as can be seen in this post in Salesforce success community and this post in Salesforce StackExchange. This line here is where I would start:

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

There are references to an sobject field awsKeySet[0].Name__c and a variable fname that you resolve into your URL string.

Are you certain there are no spaces or unescaped characters in the underlying value of either of those?

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM