Angularjs 为什么http可以工作,但http post不能?

Angularjs 为什么http可以工作,但http post不能?,angularjs,Angularjs,我已经在PostMan中测试了所有web API,它们都工作得很好 在我的js代码中,http put起作用,我可以编辑现有记录 http post几乎完全相同,但每次我提交时,服务器端都返回空值 在测试时,我还将所有对象属性输出到控制台,它们也都很好地写入控制台: CreateController.Save function fired!!! WebMarkService.js:30 Create Service fired!!! WebMarkService.js:31 Name is te

我已经在PostMan中测试了所有web API,它们都工作得很好

在我的js代码中,http put起作用,我可以编辑现有记录

http post几乎完全相同,但每次我提交时,服务器端都返回空值

在测试时,我还将所有对象属性输出到控制台,它们也都很好地写入控制台:

CreateController.Save function fired!!!
WebMarkService.js:30 Create Service fired!!!
WebMarkService.js:31 Name is test!!!
WebMarkService.js:32 Label is test!!!
WebMarkService.js:33 NavigateUrl is test!!!
WebMarkService.js:34 WebMark is [object Object]!!!
angular.js:10695 POST http://localhost:29830/api/WebMarks/[object%20Object] net::ERR_CONNECTION_REFUSED(anonymous function) @ angular.js:10695sendReq @ angular.js:10514status.$get.serverRequest @ angular.js:10221processQueue @ angular.js:14678(anonymous function) @ angular.js:14694parent.$get.Scope.$eval @ angular.js:15922parent.$get.Scope.$digest @ angular.js:15733parent.$get.Scope.$apply @ angular.js:16030(anonymous function) @ angular.js:23486x.event.dispatch @ jquery-2.0.3.min.js:5x.event.add.y.handle @ jquery-2.0.3.min.js:5
WebMarkCreateController.js:37 -1
我在VisualStudio的调试器中有它,所以我可以看到连接被拒绝的原因

我只是想知道,对于http post,是否有一些我需要知道的东西,我可以跳过这些东西来进行http put

这应该很简单,但它是空的,这让我发疯!!!哈哈

//=============================================================================
// PUT: api/WebMarks/5
[ResponseType(typeof(void))]
public IHttpActionResult PutWebMark( int id, WebMark webMark )
//=============================================================================

//=============================================================================
// POST: api/WebMarks
[ResponseType( typeof( WebMark ) )]
public IHttpActionResult PostWebMark( WebMark webMark )
//=============================================================================

---------------------------------------------------------------

// add a service to the application module

(
function( app ) 
    {
    var WebMarkService = function( $http, webMarksApiUrl )
        {
        var getAll = function ()
            {
            return $http.get( webMarksApiUrl + "WebMarks/" );
            };

    var getById = function( id )
        {
        return $http.get( webMarksApiUrl + "WebMarks/" + id );
        };

    var update = function( webMark )//<-- works
        {
        console.log( "Update Service fired!!!" );
        console.log( "Name is " + webMark.WebMarkName + "!!!" );

        $http.defaults.headers.put[ "Content-Type" ] = "application/json"; // WORKING
        return $http.put( webMarksApiUrl + "WebMarks/" + webMark.WebMarkID, webMark );
        };

    var create = function( webMark ) //<-- does not work???
        {
        console.log( "Create Service fired!!!" );
        console.log( "Name is " + webMark.WebMarkName + "!!!" );
        console.log( "Label is " + webMark.WebMarkLabel + "!!!" );
        console.log( "NavigateUrl is " + webMark.WebMarkNavigateUrl + "!!!" );
        console.log( "WebMark is " + webMark + "!!!" );

        $http.defaults.headers.post[ "Content-Type" ] = "application/json"; //NOT WORKING
        return $http.post( webMarksApiUrl + "WebMarks/" + webMark );
        };

    var destroy = function( webMark )
        {
        console.log( "Destroy Service fired!!!" );
        console.log( "Name is " + webMark.WebMarkName + "!!!" );

        webMark.WebMarkIsDeleted = true;

        return $http.delete( webMarksApiUrl + "WebMarks/" + webMark.WebMarkID, webMark );
        };

    return { getAll: getAll, getById: getById, update: update, create: create, delete: destroy };
    };

    app.factory( "WebMarkService", WebMarkService );
    } ( angular.module( "MyWebMarks" ) ) 
)

$http.post()
中没有数据参数,您正在尝试将对象
webMark
连接到字符串url。。。@charlietfl说了些什么。简而言之:“除了我正在做的事情不同之外,所有这些事情都可以工作。”我如何正确地将webMark对象提交到http。那就发帖吧?这适用于http.put,它几乎与使用
put
delete
的方式相同。没有ID,所以将
+
更改为
“几乎相同”。。。嗯,我想还不够完全一样吧?
    public static void RegisterRoutes( RouteCollection routes )
    {
    routes.IgnoreRoute( "{resource}.axd/{*pathInfo}" );

    routes.MapRoute(
        name: "Default",
        url: "{controller}/{action}/{id}",
        defaults: new { controller = "Home", action = "Index", id = UrlParameter.Optional }
    );