[英]REST not working on ColdFusion
我覺得我必須缺少一些明顯的東西,因為REST文檔看起來是如此簡單,並且我生成的代碼似乎可以正常工作,除非我嘗試通過REST訪問它。
hello.cfc:
component rest="true" restpath="restTest"{
remote string function sayHello() httpMethod="get"{
return "Hello World";
}
}
服務映射:
我嘗試了默認的是和否,都沒有更改。
測試頁:
<html>
<head>
<title>REST Test</title>
</head>
<body>
Calling service as an object:<br>
<cfset restTest = new hello() />
<cfdump var="#restTest.sayHello()#" />
<br>
Calling service via http:<br>
<cfhttp url="http://localhost/rest/restTest" result="restResult" method="GET" />
<cfdump var="#restResult#" />
</body>
</html>
結果:
您是否嘗試訪問而不通過連接器/網絡服務器定向呼叫? 將您的項目放在/ cfusion / wwwroot /中,然后嘗試通過瀏覽器http:// localhost:8500 / rest / restTest訪問它
更改網址后,示例測試也對我有用
向REST服務發出HTTP請求時,您似乎使用了錯誤的URL。 該網址應如下所示:
http://{domain}/rest/{service mapping name}/{component level rest path}/{function level restpath}
因此,在您的情況下,正確的網址應為:
http://localhost/rest/api/restTest
有關更多信息,請閱讀此http://www.adobe.com/devnet/coldfusion/articles/restful-web-services.html
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.