using (var client = new HttpClient())
{
client.BaseAddress = new Uri(Url);
client.DefaultRequestHeaders.Accept.Clear();
client.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/xml"));
using (var task = client.PostAsJsonAsync(Url, body))
{
if (task.Result.StatusCode != HttpStatusCode.OK)
throw new Exception(task.Result.ReasonPhrase);
}
Değil Emin her yuva adresi yalnızca bir kullanım almak neden (protokol/ağ adresi/bağlantı noktası), normal olarak izin verilmektedir xx.xxx.xxx.xx: 80 hata
System.AggregateException: One or more errors occurred. ---> System.Net.Http.HttpRequestException: An error occurred while sending the request. ---> System.Net.WebException: Unable to connect to the remote server ---> System.Net.Sockets.SocketException: Only one usage of each socket address (protocol/network address/port) is normally permitted xx.xx.xx.xx:80
at System.Net.Sockets.Socket.EndConnect(IAsyncResult asyncResult)
at System.Net.ServicePoint.ConnectSocketInternal(Boolean connectFailure, Socket s4, Socket s6, Socket& socket, IPAddress& address, ConnectSocketState state, IAsyncResult asyncResult, Exception& exception)
--- End of inner exception stack trace ---
at System.Net.HttpWebRequest.EndGetRequestStream(IAsyncResult asyncResult, TransportContext& context)
at System.Net.Http.HttpClientHandler.GetRequestStreamCallback(IAsyncResult ar)
--- End of inner exception stack trace ---
--- End of inner exception stack trace ---
at System.Threading.Tasks.Task`1.GetResultCore(Boolean waitCompletionNotification)
teşekkür ederiz. Mantıklı. Farklı iş parçacıklarında birden çok HttpClient örneğim var, bir HttpClient örneğinin, diğer iş parçacığında diğer HttpClient örneği tarafından hangi ip/bağlantı noktasının kullanıldığını nasıl bildiği nasıl? –
Tekrar teşekkürler, Remy. Şimdi anlıyorum neden bu hatayı aldım. –
Henrik Nielsen'den: Normalde geçici bağlantı noktalarından kaçtığınız için. Tüm istekleriniz için aynı HttpClient örneğini yeniden deneyin. –