0
好吧,我相信我已經接近這個工作,但似乎無法讓WebAPI控制器識別,除非我在URI中傳遞參數。
我...... 角度使用這樣的$資源......這集的URL,並將此數據調用的WebAPI
var savePromise = myService.common.SaveData.save({},{ ID: saveObj.ID, Year: saveObj.Year, typeID: saveObj.TypeID, ObjectList: JSON.stringify(saveCollection) }).$promise;
服務...保存數據:$ resource(myURL,{})
的WebAPI控制器...
public class ObjectsSaveController : ApiController
{
[System.Web.Http.HttpPost]
public HttpResponseMessage POST([FromBody] int ID, int Year,
int typeID, string ObjectList) {
Request URL:myURL/api/ObjectsSave
Request Method:POST
Status Code:404 Not Found
Remote Address:[::1]:8081
Referrer Policy:no-referrer-when-downgrade
Response Headers
view source
Access-Control-Allow-Origin:*
Cache-Control:no-cache
Content-Length:791
Content-Type:application/json; charset=utf-8
Date:Mon, 28 Aug 2017 21:11:09 GMT
Expires:-1
Persistent-Auth:true
Pragma:no-cache
Server:Microsoft-IIS/8.5
X-AspNet-Version:4.0.30319
X-Powered-By:ASP.NET
Request Headers
view source
Accept:application/json, text/plain, */*
Accept-Encoding:gzip, deflate, br
Accept-Language:en-US,en;q=0.8
Cache-Control:no-cache
Connection:keep-alive
Content-Length:210
Content-Type:application/json;charset=UTF-8
Host:localhost:8081
Origin:http://localhost:8081
Pragma:no-cache
Referer:http://localhost:8081/myURL/
User-Agent:Mozilla/5.0 (Windows NT 6.3; Win64; x64) AppleWebKit/537.36
(KHTML, like Gecko) Chrome/60.0.3112.101 Safari/537.36
Request Payload
view source
{ID: 211313, Year: 2017, typeID: 7,…}
cropYear
:
2017
ID
:
211313
ObjectList
:
"[{"ID":-1,"Name":"","geoJSONShape":"{\"type\":\"Point\",\"coordinates\":
[-99.35464723335105,41.54277522419835]}"}]"
typeID
:
7
Name
如果我沒有在查詢字符串傳遞值則ApiController不會被發現。
任何幫助表示讚賞!