2

在这篇文章之后,我正在尝试创建一个从 Salesforce 到网络服务 (.Net) 的 Apex 标注 - 或者可以接收 POST 的东西。

作为新手,我不确定如何捕获POST从 Salesforce 发送的 Http。那就是我在 Salesforce 中有一个 Apex 类,它在帐户插入时触发:

public class WebServiceCallout {

    @future (callout=true)
    public static void sendNotification(String name) {

        HttpRequest req = new HttpRequest();
        HttpResponse res = new HttpResponse();
        Http http = new Http();

        req.setEndpoint('http://localhost');
        req.setMethod('POST');
        req.setBody('name='+EncodingUtil.urlEncode(name, 'UTF-8'));
        req.setCompressed(true); // otherwise we hit a limit of 32000

        try {
            res = http.send(req);
        } catch(System.CalloutException e) {
            System.debug('Callout error: '+ e);
            System.debug(res.toString());
        }

    }

}

逻辑上req.setEndpoint('http://localhost');应该替换为我的 IP 和可接受的端口

如果我想了解这一点POST,需要在 Visual Studio (.Net) 中构建什么项目?

4

1 回答 1

1

假设您有一个不会更改的公共 IP 地址,并且端口没有被防火墙等阻止......

将 IP 地址添加到 Salesforce 中的远程站点设置。这将使标注成为您的端点。

对于如何处理入站 HTTP 请求,您在 .NET 中有很多选择。您是要在 IIS 中托管它,还是只想在命令行上运行一些东西并打开一个端口?

它可以像检查 HTTP 请求并从正文中读取名称的 Web 应用程序一样简单。

于 2014-08-14T09:27:56.887 回答