从Salesforce Apex标注中捕获/查看http POST

时间:2014-08-12 06:56:23

标签: c# .net salesforce apex callout

遵循此post我尝试从Salesforce创建Apex Callout到Web服务(.Net) - 或者可以接收POST的东西。

我不确定如何捕获从Salesforce发送的Http POST。那就是我在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和可接受的port

如果我想抓住这个POST需要在Visual Studio(.Net)中构建哪个项目?

1 个答案:

答案 0 :(得分:1)

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

将IP地址添加到Salesforce中的Remote Site Settings。这样就可以将标注作为您的终点。

.NET中有很多选项可用于处理入站HTTP请求。你打算在IIS中托管这个,还是只想在命令行运行一个打开端口的东西?

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