C# form uygulamasına API bağlama

krebb

Hectopat
Katılım
24 Aralık 2018
Mesajlar
23
Merhaba, elimde C# form uygulamam var ama bu uygulamaya aşağıdaki API'ı nasıl çekeceğimi bilmiyorum yardım edebilir misiniz?

 
Merhaba, API KEY'iniz ile istek atacaksınız.
Kod:
var client = new HttpClient();
string followCode = "843914957251";
int companyId = 1;
string apiKey = "API-KEY-BURAYA";
var request = new HttpRequestMessage
{
    Method = HttpMethod.Post,
    RequestUri = new Uri("https://kargom-nerede.p.rapidapi.com/tracking"),
    Headers =
    {
        { "X-RapidAPI-Key", apiKey },
        { "X-RapidAPI-Host", "kargom-nerede.p.rapidapi.com" },
    },
    Content = new StringContent("{\r\n    \"code\": \""+followCode+"\",\r\n    \"companyId\": "+companyId+"\r\n}")
    {
        Headers =
        {
            ContentType = new MediaTypeHeaderValue("application/json")
        }
    }
};
using (var response = await client.SendAsync(request))
{
    response.EnsureSuccessStatusCode();
    var body = await response.Content.ReadAsStringAsync();
    return body;//Yanıtı string olarak döndürür.
}

Örnek kod budur. Lütfen bunu kodunuza doğrudan kopyalayıp yapıştırmayın. Sadece anlamanız için oluşturduğum bir kod ve hoş değil.
 

Geri
Yukarı