不支持的媒体类型错误415? [英] unsupported media type error 415?
本文介绍了不支持的媒体类型错误415?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在使用在anothe rmachine中用Java创建的Web服务,并在C#.net中使用rest客户端使用它,与此同时,我收到一条错误消息:远程服务器返回错误:不支持的媒体类型415"
...请解决我的问题...我正在使用控制台应用程序,代码如下
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
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]已添加代码块-OriginalGriff [/edit]
[edit]Code block added - OriginalGriff[/edit]
推荐答案
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)
{
}
}
这篇关于不支持的媒体类型错误415?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文