我想在我的应用程序中使用API
。所以我像下面这样使用它
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);
但是在使用上述api时,出现错误信息
远程服务器返回错误:(415)不支持的媒体类型。
当我调试此行代码时,会产生上述错误
string json = client.UploadString(apiUrl, inputJsonIPColoMaster);
生成的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"}]}
我不明白该错误的根本原因是什么。请帮助
答案 0 :(得分:0)
经过大量的调试和响应数据后,我从客户端获得了
尝试一下。我所做的是
$new = array_column($arr,"Price", "Sku");
var_dump($new);
例如:-较早的响应类名称是我发送的I created the Parameters with same name as the response was generating from the API
。但是API响应为IEIncrementalData
,它有11个参数。因此,我使用相同的名称和相同的参数编号创建了该类。
这样做之后,它对我有用。!