将HTML字符串作为参数发布到ASP.NET webservice

时间:2016-07-23 12:06:58

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

我在将我的角度应用程序中的html标记发布到ASP.NET Webservice时遇到问题。我想我可能不得不编码它。但即使使用编码,我也会收到内部服务器错误500。 如果我只是为postcontent变量赋值,如postcontent =" test"它完美地发布到webservice。

我已经记录并警告了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);

        });
    }

[的WebMethod]

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();

    }*/


}

1 个答案:

答案 0 :(得分:0)

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

相关问题