Hello,
I am developing SharePoint hosted app. In this application i want to "Post"data (multiple file streams as multipart form data) to the cross domain third party Rest Service which needsusername and password to pass with this POST request. I found many samples which can access the cross domain REST service with "GET" operation with no username and password. These samples work fine with GET operation and no username and password but not support my case where i want to send Username and Password and multipart form data.
I have seen the fiddler session and i though to send the Authorization header value which is the hash value of username and password combine. but this effort could not successfully passed the username and password to the rest service. Also i need to find a way to send the multipart form data to the REST service.
Following is the code i used,
var context = SP.ClientContext.get_current();
var request = new SP.WebRequestInfo();
request.set_url(
"http://mysecureRESTservice/"
);
request.set_method("POST");
// We need the response formatted as JSON.
// i have changed the hash value of authorization code. this is not actual
request.set_headers(
{ "Accept": "application/json;odata=verbose" }
,
{"Authorization": "Basic U2hhcmVwb2ludEFwcEMNY3Rzb2x1dGlvbi5uZXQ6d2tnUzJlVlRoQg=="});
response = SP.WebProxy.invoke(context, request);
// Set the event handlers and invoke the request.
context.executeQueryAsync(successHandler, errorHandler);
KhanG