Click here to Skip to main content
15,891,646 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
i am using a web service created in java in anothe rmachine and consuming it using rest client in C#.net while doing that i am getting an error saying "the remote server returned an error:unsupported media type 415"

...please fix my problem... i am using a console application and the code is as follows

C#
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Web;
using System.IO;
using System.Web;
using System.Net;
namespace ConsoleApplication1
{
    class Program
    {
        static void Main(string[] args)
        {
            do
            {
                try
                {
                    string content;
                   // Console.WriteLine("Enter Method:");
                    string Method = "POST";
                        //Console.ReadLine();

                   // Console.WriteLine("Enter URI:");
                    string uri = "http://172.18.19.171:8080/RestDrools/rest/getPerson/personXML";
                    Console.WriteLine(uri);
                    HttpWebRequest req = WebRequest.Create(uri) as HttpWebRequest;
                    req.KeepAlive = false;
                    req.Method = Method.ToUpper();

                    if (("POST,PUT").Split(',').Contains(Method.ToUpper()))
                    {
                       // Console.WriteLine("Enter XML FilePath:");
                        string FilePath = "D://xyz.xml";
                        Console.WriteLine(FilePath);
                            //Console.ReadLine();
                        content = (File.OpenText(@FilePath)).ReadToEnd();

                        byte[] buffer = Encoding.ASCII.GetBytes(content);
                        req.ContentLength = buffer.Length;
                        req.ContentType = "applicaton/xml";
                        Stream PostData = req.GetRequestStream();
                        PostData.Write(buffer, 0, buffer.Length);
                        PostData.Close();
                    }

                    HttpWebResponse resp = req.GetResponse() as HttpWebResponse;

                    Encoding enc = System.Text.Encoding.GetEncoding(1252);
                    StreamReader loResponseStream =
                    new StreamReader(resp.GetResponseStream(), enc);

                    string Response = loResponseStream.ReadToEnd();

                    loResponseStream.Close();
                    resp.Close();
                    Console.WriteLine(Response);
                }
                catch (Exception ex)
                {
                    Console.WriteLine(ex.Message.ToString());
                }

                Console.WriteLine();
                Console.WriteLine("Do you want to continue?");
            } while (Console.ReadLine().ToUpper() == "Y");
        }
    }
}


[edit]Code block added - OriginalGriff[/edit]
Posted
Updated 6-Nov-12 0:32am
v2

1 solution

C#
using System;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;

public partial class _Default : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
    }

}
 
Share this answer
 
v2

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900