2015-04-04 107 views
0

我请求使用角度js的Web API,但我得到了404响应。获得和后期工作很大,但。可能是什么原因。我瞪大眼睛,人们都在谈论Webdev的我试图几乎一切仍是愚蠢404返回的Web API PUT 404

请求者和API都是在同一个域,http://locathost/apihttp://localhost/app

服务器端代码

// PUT: api/Projects/5 
    [ResponseType(typeof(void))] 
    public async Task<IHttpActionResult> PutProject(int id, Project project) 
    { 
     if (!ModelState.IsValid) 
     { 
      return BadRequest(ModelState); 
     } 

     if (id != project.Id) 
     { 
      return BadRequest(); 
     } 

     db.Entry(project).State = EntityState.Modified; 

     try 
     { 
      await db.SaveChangesAsync(); 
     } 
     catch (DbUpdateConcurrencyException) 
     { 
      if (!ProjectExists(id)) 
      { 
       return NotFound(); 
      } 
      else 
      { 
       throw; 
      } 
     } 

     return StatusCode(HttpStatusCode.NoContent); 
    } 

AngularJs服务

mediaApp.factory('Api', function ($resource) { 
var data = $resource('http://localhost/api/projects/:id', {id: '@id'}, { 
    update:{ 
     method:'PUT' 
    } 
}); 
return data; 

});

angularjs控制器调用它

Api.update({ id: 9}, {id:9,projectName: 'test', number: 'test', dateTime: 'test', inspector: 'test', neighborhood: 'test', field1: 'test', field2: 'test' }); 

和错误,我得到

Remote Address:127.0.0.1:8888 
Request URL:http://localhost/api/projects/9 
Request Method:PUT 
Status Code:404 Not Found 
Request Headersview source 
Accept:application/json, text/plain, */* 
Accept-Encoding:gzip, deflate, sdch 
Accept-Language:en-US,en;q=0.8 
Content-Length:136 
Content-Type:application/json;charset=UTF-8 
Host:localhost 
Origin:http://localhost 
Proxy-Connection:keep-alive 
Referer:http://localhost/App/ 
User-Agent:Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/40.0.2214.94 Safari/537.36 
Request Payloadview source 
{id: 9, projectName: "test", number: "test", dateTime: "test", inspector: "test", neighborhood: "test",…} 
dateTime: "test" 
field1: "test" 
field2: "test" 
id: 9 
inspector: "test" 
neighborhood: "test" 
number: "test" 
projectName: "test" 
Response Headersview parsed 
HTTP/1.1 404 Not Found 
Cache-Control: private 
Content-Type: text/html; charset=utf-8 
Server: Microsoft-IIS/7.5 
X-Powered-By: ASP.NET 
Date: Sat, 04 Apr 2015 05:03:54 GMT 
Content-Length: 5270 
+0

您可能需要在您的服务URL指定的端口号(即IIS上运行的端口) – 2015-04-04 05:57:48

+0

的GET和POST我你的意思是8888的角度服务?我试过但没有工作。默认端口是80,它也没有帮助。 – johnny 2015-04-04 06:04:30

+0

你试过了吗:http://stackoverflow.com/questions/10099270/asp-net-web-api-returns-404-for-put-only-on-some-servers – 2015-04-04 09:20:56

回答