【发布时间】:2013-11-29 14:44:57
【问题描述】:
美好的一天。
在这个问题上我真的需要帮助。我在这里尝试了所有可能的选项。
我在使用 C# 的 Outlook 加载项中使用 REST API。该代码以一种方式将 Outlook 项目链接到 CRM 记录。加载项工作 100% 正常,但经过几次调用后,我不断收到错误消息“操作已超时”。
当我使用 Google Chrome 应用程序“高级 REST 客户端”时,我可以将相同的请求一个接一个地发布 50 次,而不会出现超时错误。
在加载项中,我使用 POST、GET 和 PATCH HttpWebRequest,但我得到了所有这些错误。错误发生在代码行 System.IO.Stream os = req.GetRequestStream();
方法如下:
public static string HttpPatch(string URI, string Parameters)
{
var req = (System.Net.HttpWebRequest)System.Net.WebRequest.Create(URI);
if (GlobalSettings.useproxy.Equals("true"))
{
req.Proxy = WebRequest.DefaultWebProxy;
req.Credentials = new NetworkCredential(GlobalSettings.proxyusername, GlobalSettings.proxypassword, GlobalSettings.proxydomain);
req.Proxy.Credentials = new NetworkCredential(GlobalSettings.proxyusername, GlobalSettings.proxypassword, GlobalSettings.proxydomain);
}
req.Headers.Add("Authorization: OAuth " + GlobalSettings.token.access_token);
req.ContentType = "application/json";
req.Method = "PATCH";
byte[] data = System.Text.Encoding.Unicode.GetBytes(Parameters);
req.ContentLength = data.Length;
using (System.IO.Stream os = req.GetRequestStream())
{
os.Write(data, 0, data.Length);
os.Close();
}
WebResponse resp;
try
{
resp = req.GetResponse();
}
catch (WebException ex)
{
if (ex.Message.Contains("401"))
{
}
}
}
【问题讨论】:
标签: c# rest outlook add-in outlook-addin