0

我有一个与 Salesforce 连接的 Outlook 插件应用程序。我正在尝试从 SF API 请求一些数据,这些数据通常会在不到 1 秒的时间内返回结果,但使用我的代码需要 5-15 秒才能完成。

我也尝试将代理设置为空。

这是我的代码:

    System.Net.ServicePointManager.SecurityProtocol = System.Net.SecurityProtocolType.Tls12;
    System.Net.WebRequest req = System.Net.WebRequest.Create(URI);
    if (includeCustomHeader == true)
    {
        req.Headers.Add("Authorization: OAuth " + ServiceManager.Token.access_token);
        req.Headers.Add("X-PrettyPrint:1");
        req.ContentType = "application/json";
    }
    else
    {
        req.ContentType = "application/x-www-form-urlencoded";
    }
    req.Method = "POST";
    req.Proxy = null;

    byte[] data = System.Text.Encoding.ASCII.GetBytes(payload);
    req.ContentLength = data.Length;
    using (var responseStream = req.GetRequestStream())
    {
        responseStream.Write(data, 0, data.Length);
    }

     //here it's taking from 5-15 seconds, each request gets a batch of 200 records
    using (var response = req.GetResponse())
    {
        return new System.IO.StreamReader(response.GetResponseStream()).ReadToEnd();
    }

不知道我错过了什么,或者还有其他原因吗?建议?

4

0 回答 0