Я новичок в xamarin и Rest API.
Я пытаюсь вызвать Rest API из кода Xamrine IOS следующим образом.Мой девиз - получить список (из API) и отобразить в виде списка (устройство).Но это дает мне ошибку «Bad Request».но когда положить тот же URL в POSTMAN, дает мне правильный ответ.Пожалуйста, помогите мне здесь.
Изображение звонка почтальона
Звонок от почтальона
URL: http://localhost/MobileAppAPI/
Код клиента:
static List<AuditModel> _audits = new List<AuditModel>();
public static string GetAudits()
{
string URL = "http://localhost/MobileAppAPI/api/Values/Get?id=1000";
string data = CreateObject(URL);
return APIHelper.APIHelper.CreateObject(URL);
}
public static string CreateObject(string URL)
{
HttpWebRequest request = (HttpWebRequest)WebRequest.Create(URL);
request.Method = "GET";
request.ContentType = "application/json";
ServicePointManager.SecurityProtocol = SecurityProtocolType.Ssl3;
try
{
using (Stream webStream = request.GetRequestStream())
using (StreamWriter requestWriter = new StreamWriter(webStream, System.Text.Encoding.ASCII))
{
requestWriter.Write("");
}
WebResponse webResponse = request.GetResponse();
using (Stream webStream = webResponse.GetResponseStream())
{
if (webStream != null)
{
using (StreamReader responseReader = new StreamReader(webStream))
{
string response = responseReader.ReadToEnd();
return response;
}
}
}
}
catch (Exception e)
{
Console.Out.WriteLine("-----------------");
Console.Out.WriteLine(e.Message);
return e.Message;
}
return "";
}
Код API:
// GET api/values/5
public string Get(int id)
{
return "value";
}
Исключение:
Unhandled Exception:
System.Net.WebException: Error: ConnectFailure (Connection refused)