【发布时间】:2017-09-02 08:08:56
【问题描述】:
我正在从 .Net Web API 中创建的 xamarin 表单 application.Web API 获取 WEB.API。但我收到错误
{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 也从浏览器和邮递员提供正确的输出。 我正在使用下面的代码来获取 web 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结果吗?可能格式输入参数错误 -
格式正确。我已经直接测试了URI结果。它工作正常。
标签: c# asp.net-mvc xamarin asp.net-web-api