【问题标题】:Posting HTML string as parameter to ASP.NET webservice将 HTML 字符串作为参数发布到 ASP.NET Web 服务
【发布时间】:2016-07-23 12:06:58
【问题描述】:

我在将 html 标记从我的 Angular 应用程序发布到我的 ASP.NET Web 服务时遇到问题。我发现我可能不得不对其进行编码。但即使使用编码,我也会收到内部服务器错误 500。 如果我只是为 postcontent 变量分配一个值,例如 postcontent="test" 它会完美地发布到 web 服务。

我已经记录并提醒 postcontent 变量,看看它是否被编码并且确实如此。

很明显,网络服务没有收到我的 html 字符串,我想知道为什么。下面是我的代码 $scope.CreatePost = function () {

        var graveId = $location.search()['gravid'];

        // get CKEDITOR value is structured like <p>placeholder</p>
        var getcontent = CKEDITOR.instances['postEditor'].getData(); 
        var postcontent = escape(getcontent);

        $http({
            method: 'POST',
            url: 'http://localhost:51113/WebService.asmx/OpretPost',
            data: "username=" + userName + "&password=" + passWord + "&graveId=" + graveId + "&content=" + postcontent,
            headers: { 'Content-Type': 'application/x-www-form-urlencoded;  charset=utf-8' }  
        }).then(function (response) {
            console.log(response.data);

        });
    }

[网络方法]

public void OpretPost(string username, string password, string graveId, string content)
{
    /*Context.Response.Write(content);
    var Customer = (from x in db._Users where x.UserPassword == password && x.UserName == username select x);
    if (Customer.Count() > 0)
    {
        _Post nypost = new _Post
        {
            FK_GraveId = int.Parse(graveId),
            FK_UserId = Customer.Single().UserId,
            PostContent = content,
            PostDate = DateTime.Now


        };
        db._Posts.InsertOnSubmit(nypost);
        db.SubmitChanges();

    }*/


}

【问题讨论】:

    标签: c# asp.net angularjs web-services post


    【解决方案1】:

    如果您希望在 POST 请求中使用.then,WebMethod 必须返回一个值。尝试将 void 更改为字符串,然后返回一个有效的字符串,例如:“OK”。

    【讨论】:

    • 没有没有解决问题。如果 postcontent 变量不包含 html,则该函数可以正常工作,但无论如何尝试都没有运气。不过感谢您的提示
    猜你喜欢
    • 1970-01-01
    • 2011-09-26
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-04-09
    • 2017-07-24
    • 2017-12-24
    相关资源
    最近更新 更多