我已经测试了帖子中的所有网络api,他们都工作正常
在我的角度js代码中,http put工作,我可以编辑现有记录
http帖子几乎完全相同,但每次我提交服务器端都会返回null
我还在测试时将所有对象属性输出到控制台,并且它们也都可以正常写入控制台:
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
我在visual studio的调试器中有它,所以我可以看到连接被拒绝的原因。
我只是想知道我是否需要http发布的内容,我可以跳过http放置?
这应该是如此简单,但它是空的,它让我疯了!洛尔
//=============================================================================
// 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" ) )
)
// ============================================= ==============================
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 }
);