我从xamarin表单应用程序中获取WEB.API。在.Net Web API中创建Web API。但我得到错误从ASP.Net Web Api中获取数据时获取403状态
{StatusCode: 403, ReasonPhrase: 'ModSecurity Action', Version: 1.1, Content: System.Net.Http.StreamContent, Headers:
{
Server: Microsoft-IIS/8.5
X-Powered-By: ASP.NET
X-Powered-By-Plesk: PleskWin
Date: Sat, 02 Sep 2017 07:59:38 GMT
Content-Type: text/html
Content-Length: 2684
}}
相同的URL从浏览器和邮递员也给予适当的输出。 我正在使用下面的代码来获取网页API。我没有得到确切的发生。
string RestUrl = "http://msystemtest.msystem.co/api/Users?userId={0}&pass={1}";
var uri = new Uri(string.Format(RestUrl, uid, pass));
string resp = string.Empty;
var response = await client.GetAsync(uri);
string statHold = string.Empty;
if(response.IsSuccessStatusCode)
{
var content = await response.Content.ReadAsStringAsync();
resp = JsonConvert.DeserializeObject<string>(content);
}
如果“http://msystemtest.msystem.co/api/Users?userId=test&pass=1”这个URL直接从浏览器和邮递员其给予适当的输出运行。
你检查过'uri'结果吗?也许格式有错误的输入参数 – Stefan
格式是正确的。我已经直接测试了URI结果。它的工作正常。 –