【发布时间】:2017-12-12 15:00:27
【问题描述】:
就像在标题中一样。我有这个错误的问题。我正在尝试制作将连接到“远程”数据库的移动应用程序。我正在使用来自所有互联网的一些提示,我也在寻找这里但找不到解决方案。
我现在遇到的主要问题是 RestClient - 这会引发此错误。 WebService 工作正常,正如浏览器 xml 文件中显示的那样,MVC5 控制器也正确地从数据库中获取数据。
代码取自 NuGetPack,名为“Plugin.RestClient”:
private const string WebServiceUrl = "http://localhost:50397/api/books/";
public async Task<List<T>> GetAsync()
{
try
{
var httpClient = new HttpClient();
var json = await httpClient.GetStringAsync(WebServiceUrl);
var taskModels = JsonConvert.DeserializeObject<List<T>>(json);
return taskModels;
}
catch (HttpRequestException e)
{
String blad = e.InnerException.Message;
blad += "asdasd";
}
return null;
}
我想与 db 建立正确的连接,以便在服务器的 ListView 数据中查看。 现在......我只是得到空白列表,在写了 try/catch 之后我看到有消息:
“发送请求时出错”
【问题讨论】:
-
你看
InnerException了吗? -
blad = "错误:ConnectFailure (Connection denied)" 但 IInnerExcaption 值为:"{System.Net.WebException}"
-
您可能需要在请求中添加
Authorization header, -
我的WebService的Web.config中有connectionString,还不够吗?
-
WebService 和 DB 之间的连接没问题,但我猜 RestClient 中的 HttpClient 不想连接 WebService
标签: c# android xamarin xamarin.forms httpclient