我有一个APEX方法试图将表单发布表单到SFDC的APEX代码中的远程端点。
所有内容似乎都正确编码,服务器发回200响应,但附件未随请求到达... SFDC是否在发送之前删除了帖子正文的内容?
HttpRequest req = new HttpRequest();
req.setHeader('Authorization','Basic '+EncodingUtil.base64Encode(Blob.valueOf('removed:removed')));
req.setHeader('Content-Type','multipart/form-data; boundary=-----------------------------153501500631101');
req.setHeader('X-Atlassian-Token','nocheck');
req.setMethod('POST');
req.setEndpoint(endPoint+'issue/'+c.Internal_Bug_Number__c+'/attachments');
String body = '-----------------------------153501500631101\r\n';
body = body + 'Content-Disposition: form-data; name="Filedata"; filename="'+attachments[0].Name+'"\r\n';
body = body + 'Content-Type: '+attachments[0].ContentType+'\r\n';
body = body + 'Content-transfer-encoding: base64\r\n\r\n';
body = body + attachments[0].Body+ '\r\n';
body = body + '-----------------------------153501500631101--\r\n';
req.setBody(body);
答案 0 :(得分:4)
试试这个解决方案。这是我提出的Blob + HttpResponse的混乱解决方案。 http://enreeco.blogspot.it/2013/01/salesforce-apex-post-mutipartform-data.html
答案 1 :(得分:0)
您应该能够使用EncodingUtil.urlEncode来确保形式参数。见https://developer.salesforce.com/docs/atlas.en-us.apexcode.meta/apexcode/apex_classes_restful_encodingUtil.htm