【问题标题】:Passing json data to a WebApi with special characters将 json 数据传递给带有特殊字符的 WebApi
【发布时间】:2016-01-23 19:54:02
【问题描述】:

我遇到了问题。

我有一个字符串值,我传递给web api 控制器。

如果我通过"myValue",它在控制器中接收为"myValue",但如果我通过"&&myValue",则接收为null

有什么想法吗?

代码:

网络客户端

factory.downloadStrudentReport = function(date, Name) {
    $rootScope.$broadcast('dowload', _url + 'GetStudentPdfReport', { date: date, Nanme: Name});
};

服务器

[HttpGet]
[Route("GetStudentPdfReport")]
public HttpResponseMessage GetStudentPdfReport(DateTime date, string stuName)
}

 //////////////
{

另一个帖子, Passing json data to a WebApi with special characters results to null

说,client.Encoding = Encoding.UTF8; 但不确定在哪里? 有什么想法吗?

【问题讨论】:

  • 请向我们展示您的代码。

标签: json asp.net-mvc-4 asp.net-web-api


【解决方案1】:

使用encodeURIComponent 函数对值进行编码。

【讨论】:

    猜你喜欢
    • 2014-07-08
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2019-06-12
    相关资源
    最近更新 更多