简体   繁体   中英

Trying to Post data to my Rest API

I have a REST API and I need to poost base 64 data to it from my Javascript.

This is my code-behind:

[HttpPost]
[Route("Services/Image/Upload")]
public void Upload(string imageData)
{
    does stuff
}

 var url = "http://informedworker.co.uk/api/Services/Image/Upload?" +"imageData=" +  base64;

$(document).ready(function () {
    $.post(url)
        .done(function (url) {
            // On success, 'data' contains a list of products.
            $("#error").html("Done");
        })
     .fail(function (jqXHR, textStatus, err) {
         $('#error').html('Error: ' + err);
     });
});

but I get an error 'not found'.

Is it the way I am passing my parameters?

You're POST excpects a link like "Services/Image/Upload?imageData=", but you're link looks like "Services/Image/Upload?base64=imageData="

You need to pass the base64 value into an object called imageData

$(document).ready(function () {
var imageData = base64;
$.post(url, imageData)
    .done(function (url) {
        // On success, 'data' contains a list of products.
        $("#error").html("Done");
    })
 .fail(function (jqXHR, textStatus, err) {
     $('#error').html('Error: ' + err);
 });
});

or write the the called url like

$(document).ready(function () {
$.post(url + "?imageData=" + base64)
    .done(function (url) {
        // On success, 'data' contains a list of products.
        $("#error").html("Done");
    })
 .fail(function (jqXHR, textStatus, err) {
     $('#error').html('Error: ' + err);
 });
});

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM