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!!!