简体   繁体   English

远程服务器返回错误:(415)在asp.net中使用API​​的不支持的媒体类型

[英]The remote server returned an error: (415) Unsupported Media Type using API in asp.net

I want to use an API in my application. 我想在我的应用程序中使用API So I m using it like below 所以我像下面这样使用

IEIncrementalData objIncrement = new IEIncrementalData();
IEIncrementalData[] arrIncrementData = new IEIncrementalData[1];

objIncrement.SAPID = Convert.ToString(grdDisplayFCAData.Rows[gvrow.RowIndex].Cells[0].Text).Replace(" ","");
objIncrement.SiteRFEIDate = Convert.ToString(grdDisplayFCAData.Rows[gvrow.RowIndex].Cells[8].Text).Replace(" ", "");
objIncrement.SiteRFSDate = Convert.ToString(grdDisplayFCAData.Rows[gvrow.RowIndex].Cells[9].Text).Replace(" ", "");
objIncrement.ID_OD = Convert.ToString(grdDisplayFCAData.Rows[gvrow.RowIndex].Cells[1].Text).Replace(" ", "");
objIncrement.ID_OD_CHANGEDATE = Convert.ToString(grdDisplayFCAData.Rows[gvrow.RowIndex].Cells[2].Text).Replace(" ", "");

if (string.IsNullOrEmpty(Convert.ToString(grdDisplayFCAData.Rows[gvrow.RowIndex].Cells[4].Text).Replace(" ", "")))
{
    objIncrement.NoofRRHBase = "0";
}
else 
{
    objIncrement.NoofRRHBase = Convert.ToString(grdDisplayFCAData.Rows[gvrow.RowIndex].Cells[4].Text).Replace(" ", "");
}

objIncrement.SiteStatus = "".Replace(" ", "");
objIncrement.SiteDropDate = "".Replace(" ", "");
objIncrement.RRH_CHAGEDDATE = Convert.ToString(grdDisplayFCAData.Rows[gvrow.RowIndex].Cells[5].Text).Replace(" ", "");
objIncrement.TENANCY_COUNT = Convert.ToString(grdDisplayFCAData.Rows[gvrow.RowIndex].Cells[6].Text).Replace(" ", "");
objIncrement.TENANCY_CHANGEDDATE = Convert.ToString(grdDisplayFCAData.Rows[gvrow.RowIndex].Cells[7].Text).Replace(" ", "");

arrIncrementData[0] = objIncrement;

string apiUrl = ConfigurationManager.AppSettings["WebApiUrl"].ToString();
var inputIPColoMaster = new
{
    IEIncrementalData = arrIncrementData,
};
string inputJsonIPColoMaster = (new JavaScriptSerializer()).Serialize(inputIPColoMaster);
WebClient client = new WebClient();
client.Headers["Content-type"] = "application/json";
client.Encoding = Encoding.UTF8;
string json = client.UploadString(apiUrl, inputJsonIPColoMaster);
DataTable dtRes = new DataTable();
string GISSendDate = System.DateTime.Now.Date.ToString("dd-MM-yyyy", new System.Globalization.CultureInfo("en-US"));
StringReader sr = new StringReader(json);
dtRes = JsonConvert.DeserializeObject<DataTable>(json);

But while using the mentioned api, I am getting error as 但是在使用上述api时,出现错误

The remote server returned an error: (415) Unsupported Media Type. 远程服务器返回错误:(415)不支持的媒体类型。

the above error generated when I debug this line of code, 当我调试此行代码时,产生了以上错误,

string json = client.UploadString(apiUrl, inputJsonIPColoMaster);

The generated json is below:- 生成的json如下:

{"IEIncrementalData":[{"SAPID":"I-PB-AMRR-ENB-I042","SiteRFEIDate":"23/10/2018","SiteRFSDate":"Approved","ID_OD":"","ID_OD_CHANGEDATE":"","NoofRRHBase":"24/10/2018","SiteStatus":"","SiteDropDate":"","RRH_COUNT":null,"RRH_CHAGEDDATE":"","TENANCY_COUNT":"","TENANCY_CHANGEDDATE":"23/10/2018"}]}

I don't understand what is exactly the error's root cause. 我不明白该错误的根本原因是什么。 Please help 请帮忙

After so much of debugging and response data which I got from the client. 经过大量的调试和响应数据,这些都是我从客户端获得的。

Gave this a try. 尝试一下。 What I did is 我所做的是

I created the Parameters with same name as the response was generating from the API

For ex:- Earlier the response class name was IEIncrementalData which I was sending. 例如:-较早的响应类名称是我发送的IEIncrementalData But the API response was SiteData and it has 11 parameters. 但是API响应是SiteData ,它有11个参数。 So I created the class with same name and same no of parameters. 因此,我使用相同的名称和相同的参数编号创建了该类。

After doing that It worked for me.!! 之后,它为我工作。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 远程服务器返回错误:(415)不支持的媒体类型 - The remote server returned an error: (415) Unsupported Media Type System.Net.WebException:远程服务器返回错误:(415)UNSUPPORTED MEDIA TYPE - System.Net.WebException : The remote server returned an error: (415) UNSUPPORTED MEDIA TYPE 错误 415:不支持的媒体类型 - ASP.NET MVC - Error 415: Unsupported Media Type - ASP.NET MVC HTTPWebRequest GET错误远程服务器返回错误:(415)不支持的媒体类型 - HTTPWebRequest GET error The remote server returned an error: (415) Unsupported Media Type POST到内容类型为x-www-form-urlencoded的asp.net Web API会引发错误415不支持的媒体类型 - POST to asp.net web api with content type x-www-form-urlencoded raises error 415 unsupported media type 415 不支持的媒体类型 asp.net 核心 - 415 Unsupported Media Type asp.net core ASP.NET 核心 WebAPI:不支持的媒体类型 - HTTP 415 - ASP.NET Core WebAPI: Unsupported Media Type - HTTP 415 415(不支持的媒体类型)将数据从 angular9 传递到 asp.net web api - 415(unsupported media type) when passing data from angular9 to asp.net web api Web API ASP.NET 核心发布请求 415 不支持的媒体类型 - Web API ASP.NET Core Post Request 415 Unsupported Media Type WebClient.UploadFile 到 IIS 7 中托管的 ASP.NET MVC 产生 HTTP 415:不支持的媒体类型错误 - WebClient.UploadFile to ASP.NET MVC hosted in IIS 7 produces HTTP 415: Unsupported media type error
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM