从salesforce.com访问本地nodejs服务器

时间:2013-06-19 12:22:32

标签: node.js salesforce apex-code force.com

我使用nodejs在我的机器中设置了本地服务器。像这样的东西:

var fs = require("fs");
var config = JSON.parse(fs.readFileSync("config.json"));
var host = config.host;
var port = config.port;
var express = require("express");

var app = express();
app.get("/",function(request,response){
    response.send('thanks for visiting my  site');
});
app.listen(port, host);

现在,如果我向此服务器发送http请求,则会收到502 seervice unavailable响应。

HttpRequest req = new HttpRequest();
 req.setEndpoint('http://localhost:4555/');
 req.setMethod('GET');
 Http http = new Http();
 HTTPResponse res = http.send(req);

我还在远程站点设置中添加了localhost url,但我仍然无法拨打任何电话。知道如何去做吗?

1 个答案:

答案 0 :(得分:3)

localhost是一个相对地址,它解析的机器取决于它所使用的位置,所以当你在apex代码中使用localhost(在salesforce服务器上运行)时,它试图与自己说话而不是你的nodejs主机。您需要为主机提供可公开解析的名称或IP地址,并在您的顶点代码中使用它。