Plugins HttpWebRequest.GetRequestStream()在MS Dynamics CRM插件中不起作用

Plugins HttpWebRequest.GetRequestStream()在MS Dynamics CRM插件中不起作用,plugins,xmlhttprequest,dynamics-crm-online,get-request,Plugins,Xmlhttprequest,Dynamics Crm Online,Get Request,我已经编写了一个插件,试图在其中获得XML响应。 这是我的代码: // Set the Method property of the request to POST. string strXMLServer = "xxx"; var request = (HttpWebRequest)WebRequest.Create(strXMLServer); request.Method = "POST"; // Set the ContentType property of the WebReques

我已经编写了一个插件,试图在其中获得XML响应。 这是我的代码:

// Set the Method property of the request to POST.
string strXMLServer = "xxx";
var request = (HttpWebRequest)WebRequest.Create(strXMLServer);
request.Method = "POST";

// Set the ContentType property of the WebRequest.
request.ContentType = "xyz";

// Assuming XML is stored in strXML
byte[] byteArray = Encoding.UTF8.GetBytes(strXML);

// Set the ContentLength property of the WebRequest.
request.ContentLength = byteArray.Length;

//(LINE 5) Get the request stream
Stream dataStream = request.GetRequestStream();

// Write the data to the request stream. 
dataStream.Write(byteArray, 0, byteArray.Length);
// Close the Stream object.
dataStream.Close();
这段代码在控制台应用程序中编写时运行良好。但是,当我将相同的代码复制到类库(插件)并尝试使用插件探查器对其进行调试时,应用程序在到达时会突然停止(第5行) i、 e.At
Stream dataStream=request.GetRequestStream()

GetRequestStream()函数不适用于插件,但可以在控制台中正常工作

任何帮助都将不胜感激:)

提前感谢


注意:我使用的是Dynamics 365在线试用版

在使用web请求构建插件时,需要考虑以下几点。首先,您需要使用WebClient,因为它受到Microsoft产品的广泛支持

其次,您的URL需要是一个DNS名称,而不是IP地址,因为这是一个沙盒模式下的托管插件

来自Microsoft网站的示例:

阅读材料: