Click here to Skip to main content
11,934,389 members (54,309 online)
Rate this:
Please Sign up or sign in to vote.
See more: C# .NET REST Client
i am using a web service created in java in anothe rmachine and consuming it using rest client in 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

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)
                    string content;
                   // Console.WriteLine("Enter Method:");
                    string Method = "POST";

                   // Console.WriteLine("Enter URI:");
                    string 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";
                        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);
                    HttpWebResponse resp = req.GetResponse() as HttpWebResponse;
                    Encoding enc = System.Text.Encoding.GetEncoding(1252);
                    StreamReader loResponseStream =
                    new StreamReader(resp.GetResponseStream(), enc);
                    string Response = loResponseStream.ReadToEnd();
                catch (Exception ex)
                Console.WriteLine("Do you want to continue?");
            } while (Console.ReadLine().ToUpper() == "Y");

[edit]Code block added - OriginalGriff[/edit]
Posted 6-Nov-12 1:18am
Edited 6-Nov-12 1:32am

1 solution

Rate this: bad
Please Sign up or sign in to vote.

Solution 1

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)

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

  Print Answers RSS
Top Experts
Last 24hrsThis month

Advertise | Privacy | Mobile
Web04 | 2.8.151126.1 | Last Updated 6 Nov 2012
Copyright © CodeProject, 1999-2015
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100