API службы мобильной связи Azure - export.put вызывает повреждение арабского текста

У меня есть функция на стороне клиента, которая вызывает API Azure Mobile Service (AMS) для обновления столбца в одной из моих таблиц AMS:

azureMobileClient.updateCustomerUser = function (phonenumber, UpdatedJson) {
    azureMobileClient.azureMSC.invokeApi("customer", {
        parameters: {
            phonenumber: phonenumber, jsondata: JSON.stringify(UpdatedJson)
        },
        method: "put"
    }).done(function (results) {
        console.log("updated customer json", UpdatedJson);
        console.log("updated customer result", results.result);
    }, function (error) {
        alert(error.message);
    });
}

А вот код export.put в моем API на портале Azure:

exports.put = function(request, response) {
console.log("customer/put");

var phonenumber = request.query.phonenumber;
var jsondata = request.query.jsondata;

console.log("customer/put phonenumber: " + phonenumber);
console.log("customer/put jsondata: " + jsondata);
console.log("customer/put request.query.jsondata: " + request.query.jsondata);

request.service.tables.getTable('User').where({ phonenumber: phonenumber, usertype: "300" }).read({
    success: function(result) {

        //Does not exist  and nothing to update; return error
        if (result.length === 0) {
            console.log("customer/put: item does not exist");
            response.send(statusCodes.NOT_FOUND, {message: "customer/put: item does not exist and not thing is updated"});
        }
        //Exists; update it
        else {

            console.log("customer/put: item exists  ");
            result[0].userjsondata = jsondata;
            request.service.tables.getTable('User').update(result[0]);
            response.send(statusCodes.OK, result[0]);
        }

    }
});

};

Я пытаюсь обновить один из столбцов моей таблицы AMS, "вставив" в строку string json ("JSON.stringify") с некоторыми вставленными арабскими символами.

Моя главная проблема заключается в том, что арабские символы в строковом файле json будут повреждены в ту минуту, когда они возвращаются из вызова API.

Вот вывод console.log, который показывает строку до и после выполнения функции API:

1 ответ

Решение

Я подозреваю, что у вас есть проблемы, потому что вы передаете параметры обновления в строке запроса вместо тела запроса. Попробуйте вызвать API следующим образом:

azureMobileClient.azureMSC.invokeApi("customer", { 
    body: { phonenumber: phonenumber,  jsondata: JSON.stringify(UpdatedJson) },
    method: "put"....

а затем в ссылке на сервер сценарий request.body вместо request.query,

Другие вопросы по тегам