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 :
Finance | Project Operations, Human Resources, ...
Suggested Answer

The remote server returned an error: (415) Unsupported Media Type.

(0) ShareShare
ReportReport
Posted on by 199

Hi,

I'm getting this exception when trying to hit the "response = request.GetResponse();"

Using following piece of code

int find;
str url,aosUri,activeDirectoryTenant;
str activeDirectoryClientAppId;
str activeDirectoryClientAppSecret;
str postData,activeDirectoryResource;
str aadClientAppSecret,oAuthHeader;
str returnValue,jsonString,jsondszstr;
System.Net.HttpWebRequest request;
System.Net.HttpWebResponse response;
System.Byte[] byteArray;
System.IO.Stream dataStream;
System.IO.StreamReader streamRead;
System.IO.StreamWriter streamWrite;
System.Net.ServicePoint servicePoint;
System.Net.ServicePointManager servicePointmgr;
System.Net.HttpVersion version;
CLRObject clrObj;
Newtonsoft.Json.JsonReader reader;
System.Text.Encoding utf8;
Counter countCounter;
Object obj;
Map data;
System.Byte[] byteArraynew;

System.Net.WebHeaderCollection headers = new System.Net.WebHeaderCollection();

str byteStr = strfmt("%1:%2", "abc", "****");

new InteropPermission(InteropKind::ClrInterop).assert();

headers = new System.Net.WebHeaderCollection();

url = "">https://xyz.login";

clrObj = System.Net.WebRequest::Create(url);


request = clrObj;

request.set_Method("Post");
request.set_KeepAlive(true);
request.set_SendChunked(true);

request.set_AllowWriteStreamBuffering(false);


request.set_ContentType("application/json");
//request.set_Accept('text/plain');

utf8 = System.Text.Encoding::UTF8;
byteArraynew = utf8.GetBytes(byteStr);
byteStr = System.Convert::ToBase64String(byteArraynew);
//request.set_ContentLength(byteArraynew.get_Length());
//request.set_ContentLength(byteArraynew.Length);
headers.Add("Authorization", 'Basic ' + byteStr);

request.set_Headers(headers);

servicePoint = request.get_ServicePoint();

System.Net.ServicePointManager::set_Expect100Continue(false);

System.Net.ServicePointManager::set_SecurityProtocol(System.Net.SecurityProtocolType::Tls12);

dataStream = request.GetRequestStream();

dataStream.Write(byteArraynew,0,byteArraynew.get_Length());
dataStream.Close();
//request.set_ContentLength(byteArraynew.Length);

response = request.GetResponse();

//Ignore this part. 
dataStream = response.GetResponseStream();


streamRead = new System.IO.StreamReader(dataStream);

jsonString = streamRead.ReadToEnd();

info(strFmt("%1",jsonString));

dataStream.Close();

response.Close();

anyone familiar with this issue kindly suggest some solutions as i'm stuck

I have the same question (0)
  • nmaenpaa Profile Picture
    101,160 Moderator on at

    The first step in the investigation is to debug the code and understand what line of code causes the issue. Perhaps already that helps you resolve the problem. If not, you can post more information here and perhaps someone can assist.

  • Suggested answer
    nmaenpaa Profile Picture
    101,160 Moderator on at

    For anyone interested, seems there's much more info available in the other discussion that Zohan_93 has created: community.dynamics.com/.../calling-service-from-url-through-json-in-d365fo

    Perhaps it's good to continue the discussion there so that we don't risk having to ask same details again.

  • Zohan_93 Profile Picture
    199 on at

    Mr. Nikolaos,

    No one is giving some suggestion except Martin on previous thread, that's why i've to create a new thread as i'm stuck in it.

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 > Finance | Project Operations, Human Resources, AX, GP, SL

#1
Martin Dráb Profile Picture

Martin Dráb 565 Most Valuable Professional

#2
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 450 Super User 2025 Season 2

#3
Sohaib Cheema Profile Picture

Sohaib Cheema 250 User Group Leader

Last 30 days Overall leaderboard

Product updates

Dynamics 365 release plans