当我尝试在我的插件(在 PostUpdate 中)中执行 HTTP Post 时遇到问题。我收到“操作已超时”-错误...
下面是 C# 代码:
//PUBLISH TO ROBAROV
WebRequest webRequest = WebRequest.Create(newUri);
webRequest.Timeout = 2000;
webRequest.ContentType = "application/x-www-form-urlencoded";
webRequest.Method = "POST";
byte[] bytes = Encoding.ASCII.GetBytes(parameters);
Stream os = null;
try
{
webRequest.ContentLength = bytes.Length;
os = webRequest.GetRequestStream();
os.Write(bytes, 0, bytes.Length);
}
catch (WebException ex)
{
throw new Exception(ex.Message);
}
finally
{
if (os != null)
{
os.Close();
}
}
//ERROR HAPPENS HERE
string responseText = "";
try
{ // get the response
WebResponse webResponse = webRequest.GetResponse();
StreamReader sr = new StreamReader(webResponse.GetResponseStream());
responseText = sr.ReadToEnd().Trim();
}
catch (WebException ex)
{
throw new Exception("Error with response : " + ex.Message);
}
当我尝试获取响应时发生错误 => webRequest.GetResponse();!
我已经在一个简单的“类”库中尝试了代码,它就像一个魅力!有什么我做错了吗?HTTP Post 是指向不在同一个域中的网页....
更新:当我使用 webclient 执行以下操作时也会发生同样的情况......它在普通的“控制台”应用程序中工作:
private string HttpPostTest(string URL)
{
WebClient webClient = new WebClient();
System.Collections.Specialized.NameValueCollection formData = new System.Collections.Specialized.NameValueCollection();
formData["state"] = "yes";
byte[] responseBytes = webClient.UploadValues(URL, "POST", formData);
string Result = Encoding.UTF8.GetString(responseBytes);
return Result;
}
我在“事件查看器”中收到以下错误:
Inner Exception: System.IO.FileNotFoundException: Could not load file or assembly 'Microsoft.Crm.Setup.DiffBuilder, Version=5.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35' or one of its dependencies. The system cannot find the file specified.