たくさん おかげで私のAPI実装である
モデル
public class Cars
{
public string carName;
public string carRating;
public string carYear;
}
私のAPIコントローラ
public class DefaultController : ApiController
{
public HttpResponseMessage GetCarses()
{
List<Cars> carList = new List<Cars>();
carList.Add(new Cars
{
carName = "a",
carRating = "b",
carYear = "c"
});
carList.Add(new Cars
{
carName = "d",
carRating = "e",
carYear = "f"
});
return Request.CreateResponse(HttpStatusCode.OK, carList); ;
}
}
とのHttpClient
からの私の応答
String jsonData;
string url =
String.Format(
@" http://localhost:37266/api/Default/GetCars");
HttpWebRequest request = (HttpWebRequest)WebRequest.Create(url);
using (HttpWebResponse response = (HttpWebResponse)request.GetResponse())
{
using (Stream stream = response.GetResponseStream())
using (StreamReader reader = new StreamReader(stream))
{
jsonData = reader.ReadToEnd();
}
//Console.WriteLine(jsonData);
}
var cars = new JavaScriptSerializer().Deserialize<List<Cars>>(jsonData);
var ss = cars;
いけないAPIを呼び出す方法を、次に
protected void Application_Start()
{
//add this line if not
GlobalConfiguration.Configure(WebApiConfig.Register);
...
}
を追加することを忘れ? –
httpクライアントで@syedmhamudulhasanakashを呼び出す –