I am making an ajax request from the clientside to my web service built in web api.
Here is the client side code :
$.ajax({
url: "http://localhost:1583/api/storage/processing/v1/preview/test.docx",
type: "POST",
contentType: "application/json; charset=utf-8",
dataType: "json",
cache: false,
responseType: "json",
beforeSend: onProgress,
success: GenerateHtml,
complete: onComplete,
error: onFail
});
Here is the controller's code:
[HttpPost]
[Route(WebApiConfig.RootApiUri + "/v1/preview/{docid}")]
public async Task
- > Preview(string docid)
{
///...ommitted the code..///
}
HttpPost isn't working, however if change it to HttpGet it works.
Any help on this would be greatly appreciated. Thanks.
9 Replies
Know the answer? Post it — somebody with the same question will find it here.
Sign in to answer this question
It is the same account you read, post and publish with — and you will come straight back to this page.
Bhuvanesh MohankumarPosted May 17, 2016, 8:05 AM
Pushpendra HirwaniPosted May 17, 2016, 7:54 AM
Bhuvanesh MohankumarPosted May 17, 2016, 7:42 AM
If you are passing a JSON object, your WEB API method should receive the parameter, however here in the sample you have only string object as parameter.
public async Task
> Preview(string docid)
Bhuvanesh MohankumarPosted May 17, 2016, 7:36 AM
[AllowAnonymous], is concern only during Authentication /Authorization issue,
Hereif the issue with Authentication, then the "GET" also may not worked andunauthorized error may occurred.
Guest UserPosted May 17, 2016, 7:35 AM
Pushpendra HirwaniPosted May 17, 2016, 7:34 AM
Pushpendra HirwaniPosted May 17, 2016, 7:32 AM
Bhuvanesh MohankumarPosted May 17, 2016, 7:20 AM
GET - Requests data from a specified resource
POST - Submits data to be processed to a specified resource
Guest UserPosted May 17, 2016, 7:14 AM