web
You’re offline. This is a read only version of the page.
close
Skip to main content

Notifications

Announcements

No record found.

Community site session details

Community site session details

Session Id :
Microsoft Dynamics CRM (Archived)

Data Stream Exception

(0) ShareShare
ReportReport
Posted on by 30

Hello Community , 

Iam tring to call a Rest API by using a CRM Plugin but I go this Error <dataStream.Position' threw an exception of type 'System.NotSupportedException>

Can anyone identify the cause of the issue please ? 

Here is my Post call : 

public Object POST(string url, string jsonContent, string header)
{
HttpWebRequest request = (HttpWebRequest)WebRequest.Create(url);
request.Method = "POST";

System.Text.UTF8Encoding encoding = new System.Text.UTF8Encoding();
Byte[] byteArray = encoding.GetBytes(jsonContent);

request.ContentLength = byteArray.Length;
request.ContentType = @"application/json";

using (Stream dataStream = request.GetRequestStream())
{
dataStream.Write(byteArray, 0, byteArray.Length);
try
{

using (HttpWebResponse response = (HttpWebResponse)request.GetResponse())
{

StreamReader sr = new StreamReader(dataStream);
var serializer = new System.Web.Script.Serialization.JavaScriptSerializer();
var jsonObject = serializer.DeserializeObject(sr.ReadToEnd());
return jsonObject;
}
}
catch (WebException ex)
{
// Log exception and throw as for GET example above
throw new Exception(ManageException(ex));

}
}

}

*This post is locked for comments

I have the same question (0)
  • Verified answer
    LAMYAE Profile Picture
    30 on at

    I correct this error by using this code :

                            Stream responseStream = response.GetResponseStream();

                           StreamReader myStreamReader = new StreamReader(responseStream);

                           var serializer = new System.Web.Script.Serialization.JavaScriptSerializer();

                           var jsonObject = serializer.DeserializeObject(myStreamReader.ReadToEnd());

Under review

Thank you for your reply! To ensure a great experience for everyone, your content is awaiting approval by our Community Managers. Please check back later.

Helpful resources

Quick Links

Responsible AI policies

As AI tools become more common, we’re introducing a Responsible AI Use…

Neeraj Kumar – Community Spotlight

We are honored to recognize Neeraj Kumar as our Community Spotlight honoree for…

Leaderboard > 🔒一 Microsoft Dynamics CRM (Archived)

#1
SA-08121319-0 Profile Picture

SA-08121319-0 4

#1
Calum MacFarlane Profile Picture

Calum MacFarlane 4

#3
Alex Fun Wei Jie Profile Picture

Alex Fun Wei Jie 2

Last 30 days Overall leaderboard

Featured topics

Product updates

Dynamics 365 release plans