Quantcast
Channel: Martin Dráb's Activities
Viewing all articles
Browse latest Browse all 17532

Unsupported Media Type exception at System.Net.HttpWebRequest.GetResponse()

$
0
0

Hi ,

 I am writing code to call SOAP services from 3rd party using X++ , below is my code ;

public static void testService(str _xmlNote)
    {
        System.Net.HttpWebRequest   webRequest;
        System.Net.HttpWebResponse  webResponse;
        System.IO.Stream            stream;
        System.IO.StreamReader      streamReader;
        CLRObject                   clrObject;
        System.Byte[]               byte;
        System.Text.Encoding        utf8;
        str                         url = "http://xxxxxxxxxx";
        new InteropPermission(InteropKind::ClrInterop).assert();

        clrObject  = System.Net.WebRequest::Create( url); 
        webRequest = clrObject;

        webRequest.Method           = 'POST';
        webRequest.ContentType      = 'application/xml'; 
        webRequest.MediaType        = 'application/xml';
        webRequest.ContentLength    = byte.get_Length();

        utf8 = System.Text.Encoding::get_UTF8();
        byte = utf8.GetBytes(_xmlNote);

        stream       = webRequest.GetRequestStream();
        stream.Write(byte,0,byte.get_Length());
        

        webResponse  =  webRequest.GetResponse();
        streamReader    = new System.IO.StreamReader(stream);

        Info(streamReader.ReadToEnd());

But it throw me error at highlighted line ( in green colour) - Microsoft.Dynamics.Ax.Xpp.ClrErrorException: WebException ---> System.Net.WebException: The remote server returned an error: (415) Unsupported Media Type. at System.Net.HttpWebRequest.GetResponse()

Please suggest me .

 


Viewing all articles
Browse latest Browse all 17532

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>