I'm trying to send a string to my Web API. If I use a string literal for fileContents (adsf), it works:
var config = {
url: '/PrestoWeb/api/app/importTasks' + '?fileContents=adsf',
method: 'POST'
};
$http(config)
.then(function (response) {
// success
}, function (response) {
// fail
});
fileContents shows up correctly in the Web API:
[AcceptVerbs("POST")]
[Route("api/app/importTasks")]
public Application ImportTasks(string fileContents)
{
// fileContents is adsf
If I change the url to my variable, I get 404 Not Found:
url: '/PrestoWeb/api/app/importTasks' + '?fileContents=' + fileContents,
I also tried this:
url: '/PrestoWeb/api/app/importTasks' + '?fileContents=' + encodeURIComponent(fileContents),
And this:
url: '/PrestoWeb/api/app/importTasks' + '?fileContents=' + encodeURIComponent(JSON.stringify(fileContents)),
Still get a 404 Not Found. What am I missing?
Note: The actual fileContents variable contains a string in XML format. Here is the first part of it:
"<ArrayOfTaskBase z:Id=\"1\" z:Type=\"System.Collections.Generic.List`1[[PrestoCommon.Entities.TaskBase, PrestoCommon, Version=3.6.0.0, Culture=neutral, PublicKeyToken=null]]\" z:Assembly=\"0\"