4

I am creating a web service which send's an import request with the data to be imported to the client's server. The XML Payload have two parts. First one is an attachment which contains the XML for data. Second part is the body (Http request body) which contains the attachment name along with other tags.

Following is how I have created the Http request

HTTP auth = new HTTP();
HTTPRequest r = new HTTPRequest();
r.setEndpoint(endpointurl);
Blob headerValue = Blob.valueOf(username +':'+ password);
String authorizationHeader = 'Basic ' + EncodingUtil.base64Encode(headerValue);
system.debug('Encoder Value' + EncodingUtil.base64Encode(headerValue));
r.setHeader('Authorization', authorizationHeader);
//r.setHeader('Content-Type','application/xml');
r.setHeader('Content-Type','Multipart/Related');
r.setHeader('SOAPAction', 'http://www.taleo.com/ws/integration/toolkit/2011/05/management/IntegrationManagementService#submitDocument');
r.setMethod('POST');
r.setBody(taleoXML);

I am creating the attachment in the following way

Document xmlDoc = new Document();
xmlDoc.Name = messageID;
xmlDoc.Body = Blob.valueOf(xmlPayload);
xmlDoc.ContentType = 'xml';
xmlDoc.Type = 'xml';

How can I attach this document to my HTTP request. Does the attachment goes in the header? what are the setHeader() parameters I will have to use?

Thank you for your help!!!

1

I found this helpful link explaining in detail how to send an attachment.

http://enreeco.blogspot.it/2013/01/salesforce-apex-post-mutipartform-data.html#finalCode_multipart

1
  • this link is answer does not work, can you please tell us what is the solution. Thanks! Nov 26 '14 at 20:54

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.