简体   繁体   English

REST无法在ColdFusion上运行

[英]REST not working on ColdFusion

I feel like I must be missing something obvious because the REST documentation seems so simple and the code I produced appears to work correctly unless I try to access it via REST. 我觉得我必须缺少一些明显的东西,因为REST文档看起来是如此简单,并且我生成的代码似乎可以正常工作,除非我尝试通过REST访问它。

hello.cfc: hello.cfc:

component rest="true" restpath="restTest"{
    remote string function sayHello() httpMethod="get"{
        return "Hello World";
    }
}

Service Mapping: 服务映射:

I have tried both default yes and no with no change. 我尝试了默认的是和否,都没有更改。

CFIDE服务映射

Test Page: 测试页:

<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>

Results: 结果:

REST结果

Did you try accessing without directing the call through a connector/webserver? 您是否尝试访问而不通过连接器/网络服务器定向呼叫? Keep your project inside /cfusion/wwwroot/ and then try accessing it via browser http://localhost:8500/rest/restTest 将您的项目放在/ cfusion / wwwroot /中,然后尝试通过浏览器http:// localhost:8500 / rest / restTest访问它

Sample test also worked for me after changing the URL 更改网址后,示例测试也对我有用

enter image description here 在此处输入图片说明

It seems like you are using a wrong URL when making HTTP request to the REST service. 向REST服务发出HTTP请求时,您似乎使用了错误的URL。 The URL should be like this: 该网址应如下所示:

http://{domain}/rest/{service mapping name}/{component level rest path}/{function level restpath}

So in your case the correct URL should be: 因此,在您的情况下,正确的网址应为:

http://localhost/rest/api/restTest

For more info read this http://www.adobe.com/devnet/coldfusion/articles/restful-web-services.html 有关更多信息,请阅读此http://www.adobe.com/devnet/coldfusion/articles/restful-web-services.html

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM