.NET uygulamasından REST hizmetine erişmem gerekiyor ve bu iki paketin herhangi biriyle yapılabilir. Hangi senaryoların hangi paketlerde kullanılacağı açık değildir. Buna daha fazla ışık getiren var mı?Microsoft.Net.Http vs Microsoft.AspNet.WebApi.Client
cevap
Kısa yanıt evet, Microsoft.AspNet.WebApi.Client
kullanın.
https://www.nuget.org/packages/Microsoft.AspNet.WebApi.Client/
Bu paket System.Net.Http için biçimlendirme ve içerik müzakere için destek ekler. JSON, XML ve form URL kodlanmış veriler için destek içerir.
Microsoft.AspNet.WebApi.Client
aslında Microsoft.Net.Http
üzerine bağlıdır ve bu tür ASP.NET Web API gibi bir sığınakta hizmeti konuşmam gerek olasılıkla biraz daha içki özellikler (örneğin JSON ve XML desteği) ile HttpClient
uzanır.
Her iki paket de System.Net.Http
ad alanında çalışır ve HttpClient
sınıfının etrafında döner.
Microsoft.AspNet.WebApi.Client
paketi, HttpClient ve HttpContent (ve diğerleri) için bazı kullanışlı uzantı yöntemleri ekleyen System.Net.Http.Formatting.dll derlemesini içerir. Yani, örneğin
:
using (var client = new HttpClient())
{
var response = await client.GetAsync("http://localhost/foo/api/products/1");
response.EnsureSuccessStatusCode();
var product = await response.Content.ReadAsAsync<ProductInfo>();
}
ReadAsAsync
yöntem Microsoft.AspNet.WebApi.Client
HttpContent
nesne üzerine ekleyen bir uzantısı bir yöntemdir. Bu, yanıt JSON, XML veya kodlanmış form URL'si (daha önce bahsedilen içerik anlaşması) ise otomatik olarak çözülür ve daha sonra güçlü biçimlendirilmiş modelinize (bu durumda, ProductInfo
) serileştirilmesi için karşılık gelen biçimlendiriciyi kullanır.
Yalnızca Microsoft.Net.Http kullanmayı denediyseniz, ReadAsAsync yöntemi sizin için uygun olmaz ve yalnızca içeriği bayt veya dize gibi ham veriler olarak okuyabilir ve seri hale getirme/serileştirme işlemini kendiniz yapın.
Ayrıca yapmak zorunda kalmadan geri JSON veya XML hizmetine/POST PUT uzantısı yöntemleri almak kendin:
// Save the ProductInfo model back to the API service
await client.PutAsJsonAsync("http://localhost/foo/api/products/1", product);
Anahtar Microsoft.AspNet.WebApi.Client uzantıları:
https://msdn.microsoft.com/en-US/library/system.net.http.httpclientextensions.aspx https://msdn.microsoft.com/en-US/library/system.net.http.httpcontentextensions.aspx
WebApi'yi Http'den daha iyi düşünüyorum. https://msdn.microsoft.com/en-us/library/jj823172(v=vs.110).aspx
- 1. Microsoft.Net.Http ile veri nasıl yüklenir?
- 2. Bir ASP.NET Core uygulamasından Microsoft.AspNet.WebApi.Client kullanabilir miyiz?
- 3. ID vs UniqueID vs ClientID vs UniqueClientID vs StaticClientID?
- 4. & vs * ve | VS +
- 5. SpiderMonkey vs JavaScriptCore vs?
- 6. VS
- 7. VS
- 8. IDataErrorInfo vs ValidationRule vs Exception
- 9. cudaStreamSynchronize vs CudaDeviceSynchronize vs cudaThreadSynchronize
- 10. visualvm vs JProbe vs JProfiler
- 11. _mm_load_ps vs. _mm_load_pd vs. etc
- 12. pycuda vs theano vs pylearn2
- 13. is_numeric() vs is_float() vs is_int()
- 14. TextColor vs TextColorPrimary vs TextColorSecondary
- 15. GridView vs DataList vs için Repeater vs ListView 'in performansı
- 16. Qt: UI ile vs vs ile xml vs ile qml
- 17. Barındırma PowerShell: PowerShell vs. Runspace vs. RunspacePool vs. Pipeline
- 18. Python vs Jython vs IronPython vs wxPython arasındaki fark nedir?
- 19. Oyun geliştirmeye nereden başlayacaksınız? UIKit vs Core Animation vs QuartzCore vs OpenGL vs Cocos2D
- 20. XAML vs WPF vs Store App vs Phone App vs UWA
- 21. RhinoMock: Mocks Vs StrictMocks Vs DynamicMocks
- 22. Resim vs Fotoğraf vs. Görüntü - Adlandırma modelleri
- 23. Clojure listesi vs vektör vs set
- 24. grails def vs Nesne vs Void
- 25. CSS "::" vs ":" - sözde seçici vs psödo seçici?
- 26. arasındaki fark django.test.TestCase vs unittest vs django.utils.unittest.TestCase
- 27. Scala - plus kolon vs çift kolon (+: vs: :)
- 28. dotNetRDF VS Jena.NEt VS diğerleri ile Dotnet?
- 29. Python verimi vs vs multiple ifs
- 30. Blanket.js vs Istanbul-js vs JSCover
Aşağı seçmen için: Sorunun nesi yanlış olduğunu araştırmak ister misiniz ?! – Anil
Bu iyi bir soru. Downvoter bunu anlamadı. –