2017-06-15 16 views
-1

私は自分のWeb APIアプリケーションを持っています。これは、サーバー上の別のAPIを呼び出したいものです。どうやってやるの ?Asp.net Web APIアプリケーションからWeb APIを消費する方法

var result = url(http://54.193.102.251/CBR/api/User?EmpID=1&ClientID=4&Status=true); 
// Something like this. 
+2

可能な重複https://stackoverflow.com/questions/9620278/how-:ここにあなたのAPIを呼び出すasync方法のサンプルですdo-i-make-calls-to-a-rest-api-using-c) – CodeCaster

答えて

1

HttpClientを使用できます。

var client = new HttpClient(); 
client.BaseAddress = new Uri("http://54.193.102.251/CBR/api"); 
// here you can add additional information like authorization or accept headers 
client.DefaultRequestHeaders 
    .Accept.Add(new MediaTypeWithQualityHeaderValue("application/json")); 

// you can chose which http method to use 
var response = await client.GetAsync("User?EmpID=1&ClientID=4&Status=true"); 
if (!response.IsSuccessStatusCode) 
    return; // process error response here 

var json = await response.Content.ReadAsStringAsync(); // assume your API supports json 
// deserialize json here 
[?私はC#を使用してREST APIへの呼び出しを行うにはどうすればよい](の
関連する問題