【问题标题】:Catching/viewing the http POST from Salesforce Apex Callout从 Salesforce Apex Callout 捕获/查看 http POST
【发布时间】:2014-08-14 17:27:56
【问题描述】:

按照post,我正在尝试创建一个从 Salesforce 到 Web 服务 (.Net) 的 Apex 标注 - 或者可以接收 POST 的东西。

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

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 和可接受的port

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

【问题讨论】:

    标签: c# .net salesforce apex callout


    【解决方案1】:

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

    将 IP 地址添加到 Salesforce 中的 Remote Site Settings。这将使标注成为您的端点。

    在 .NET 中,您可以使用多种选项来处理入站 HTTP 请求。您是要在 IIS 中托管它,还是只想在命令行上运行一些东西并打开端口?

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

    【讨论】:

    • 对于任何感兴趣的人,我都选择了 WCF RESTful Web 服务方法,该方法(目前)由控制台应用程序托管/运行
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多