Geçmişte, isteğimi endpoint
ürününe gönderen bir sınıf yaptım. Şimdi, bu yöntemi dahil bir dll
oluşturmak, bu bu kütüphaneye dönüştürmek çalışıyorum kodudur: Ben client.UploadData
çağırabilir taşınabilir değil kütüphanesinde System.Net
yılındaMicrosoft.Net.Http ile veri nasıl yüklenir?
using (var client = new HttpClient())
{
string requestJson = JsonConvert.SerializeObject(data);
client.DefaultRequestHeaders.Add("token", token);
byte[] responseArray = client. 'there is no upload data method
// the bottom code is of the old method
byte[] responseArray = client.UploadData(requestURI, method, Encoding.UTF8.GetBytes(requestJson));
return Encoding.ASCII.GetString(responseArray);
}
, ama burada sadece bakın: postAsync ve putAsync, put
veya post
talebinden bağımsız olarak client
'dan server
ürününe veri göndermeme izin veren bir yöntem var mı? Şimdiden teşekkürler.
Anladım, bu konuda bir örnek bulabilirmiyim? – Sandokan
'HttpClient': PostAsJsonAsync' ve' PutAsJsonAsync' için bir uzantı yöntemi var. MSDN'de bulabilirsiniz: https://msdn.microsoft.com/en-us/library/hh944521(v=vs.118).aspx ve https://msdn.microsoft.com/en-us/library/ system.net.http.httpclientextensions.putasjsonasync (v = vs.118) .aspx – tdragon