通过android应用程序点击时发布API错误
我有一个安卓应用程序,它可以访问我的api。下面是登录post api…当我通过我的应用程序访问api时,它显示出一些错误…当我通过postman访问我的api时。它显示“415无法处理…text/xml charset=utf-8”错误 Myservice.svc.cs通过android应用程序点击时发布API错误,android,json,api,model-view-controller,wcfserviceclient,Android,Json,Api,Model View Controller,Wcfserviceclient,我有一个安卓应用程序,它可以访问我的api。下面是登录post api…当我通过我的应用程序访问api时,它显示出一些错误…当我通过postman访问我的api时。它显示“415无法处理…text/xml charset=utf-8”错误 Myservice.svc.cs public WebResponse ValidateUser(WebRequest valid) { WebResponse objWebResponse = new WebResponse();
public WebResponse ValidateUser(WebRequest valid)
{
WebResponse objWebResponse = new WebResponse();
// webRequestdto objData = new webRequestdto();
//objData = JsonConvert.DeserializeObject<webRequestdto>(valid.data);
try
{
var sqlQuery = string.Empty;
DataTable obj = null;
if (!string.IsNullOrEmpty(valid.Username) &&!string.IsNullOrEmpty(valid.Password))
//if (!string.IsNullOrEmpty(valid.data))
{
sqlQuery = @"select gen_users.UserId, gen_users.MobileNo, gen_users.EmailID, concat(Firstname, ' ', Lastname) as FullName from gen_users
where gen_users.Username='{0}' and gen_users.UserPassword = reverse('{1}') and gen_users.IsActive='Y'";
sqlQuery = string.Format(sqlQuery, valid.Username, valid.Password);
obj = DbHelper.ExecuteDataset(Globals.GetConnectionString(), CommandType.Text, sqlQuery).Tables[0];
}
if (obj.Rows.Count > 0)
{
objWebResponse.userid = Convert.ToInt32(obj.Rows[0]["UserId"]);
objWebResponse.EmailID = Convert.ToString(obj.Rows[0]["EmailID"]);
objWebResponse.FullName = Convert.ToString(obj.Rows[0]["FullName"]);
objWebResponse.MobileNo = Convert.ToString(obj.Rows[0]["MobileNo"]);
objWebResponse.status = "success";
return objWebResponse;
}
else
{
objWebResponse.status = "fail";
objWebResponse.userid = 0;
return objWebResponse;
}
}
catch (Exception ex)
{
throw new FaultException(ex.Message);
}
}
web.config
<?xml version="1.0" encoding="utf-8"?>
<configuration>
<appSettings>
<add key="aspnet:UseTaskFriendlySynchronizationContext" value="true"/>
<add key="*" value="Server=*;Database=*;User ID=*;Password=*;" />
</appSettings>
<system.web>
<compilation debug="true" targetFramework="4.5.2"/>
<httpRuntime targetFramework="4.5.2"/>
<httpModules>
<add name="ApplicationInsightsWebTracking" type="Microsoft.ApplicationInsights.Web.ApplicationInsightsHttpModule, Microsoft.AI.Web"/>
</httpModules>
</system.web>
<system.serviceModel>
<behaviors>
<serviceBehaviors>
<behavior>
<!-- To avoid disclosing metadata information, set the values below to false before deployment -->
<serviceMetadata httpGetEnabled="true" httpsGetEnabled="true"/>
<!-- To receive exception details in faults for debugging purposes, set the value below to true. Set to false before deployment to avoid disclosing exception information -->
<serviceDebug includeExceptionDetailInFaults="false"/>
</behavior>
</serviceBehaviors>
</behaviors>
<protocolMapping>
<add binding="basicHttpsBinding" scheme="https"/>
</protocolMapping>
<serviceHostingEnvironment aspNetCompatibilityEnabled="true" multipleSiteBindingsEnabled="true"/>
</system.serviceModel>
<system.webServer>
<modules runAllManagedModulesForAllRequests="true">
<remove name="ApplicationInsightsWebTracking"/>
<add name="ApplicationInsightsWebTracking" type="Microsoft.ApplicationInsights.Web.ApplicationInsightsHttpModule, Microsoft.AI.Web" preCondition="managedHandler"/>
</modules>
<directoryBrowse enabled="true"/>
<validation validateIntegratedModeConfiguration="false"/>
</system.webServer>
</configuration>
这与Android无关。问题出在你的后端。你能建议后端@Vlad MatvienkoI的错误是什么吗?我是一名Android开发人员,不是后端开发人员,所以我能说的是,你在处理请求头方面可能存在一些问题。thanx bro获取信息:)
<?xml version="1.0" encoding="utf-8"?>
<configuration>
<appSettings>
<add key="aspnet:UseTaskFriendlySynchronizationContext" value="true"/>
<add key="*" value="Server=*;Database=*;User ID=*;Password=*;" />
</appSettings>
<system.web>
<compilation debug="true" targetFramework="4.5.2"/>
<httpRuntime targetFramework="4.5.2"/>
<httpModules>
<add name="ApplicationInsightsWebTracking" type="Microsoft.ApplicationInsights.Web.ApplicationInsightsHttpModule, Microsoft.AI.Web"/>
</httpModules>
</system.web>
<system.serviceModel>
<behaviors>
<serviceBehaviors>
<behavior>
<!-- To avoid disclosing metadata information, set the values below to false before deployment -->
<serviceMetadata httpGetEnabled="true" httpsGetEnabled="true"/>
<!-- To receive exception details in faults for debugging purposes, set the value below to true. Set to false before deployment to avoid disclosing exception information -->
<serviceDebug includeExceptionDetailInFaults="false"/>
</behavior>
</serviceBehaviors>
</behaviors>
<protocolMapping>
<add binding="basicHttpsBinding" scheme="https"/>
</protocolMapping>
<serviceHostingEnvironment aspNetCompatibilityEnabled="true" multipleSiteBindingsEnabled="true"/>
</system.serviceModel>
<system.webServer>
<modules runAllManagedModulesForAllRequests="true">
<remove name="ApplicationInsightsWebTracking"/>
<add name="ApplicationInsightsWebTracking" type="Microsoft.ApplicationInsights.Web.ApplicationInsightsHttpModule, Microsoft.AI.Web" preCondition="managedHandler"/>
</modules>
<directoryBrowse enabled="true"/>
<validation validateIntegratedModeConfiguration="false"/>
</system.webServer>
</configuration>