홈>
웹 API REST 웹 서비스에 액세스하는 웹 API 클라이언트를 사용하고 있습니다.
디버깅시이를 호출 할 때 다음 오류가 발생합니다.
An error occured while sending the request (Inner Exception: The underlying conection was closed: An unexpected error occured on a send)
이것은 Visual Studio 2015에서 디버깅 할 때만 발생합니다. 디버깅없이 코드를 실행할 때는 발생하지 않습니다. .NET 4.6.1을 사용하고 있습니다.
이러한 이유는 무엇입니까? 디버깅하지 않을 때 왜 실행되고 디버깅 할 때 충돌이 발생합니다. 이 문제를 해결하는 방법과 확인할 수있는 아이디어가 있습니까?
우리는 웹 서비스 호출을하기 위해 다음 코드를 사용합니다 :
public async Task<string> GetToken(string username, string password)
{
using (var client = new HttpClient())
{
InitializeHttpClient(client);
HttpContent requestContent = new StringContent("grant_type=password&username=" + username + "&password=" + password, Encoding.UTF8, "application/x-www-form-urlencoded");
var response = await client.PostAsync("token", requestContent);
if (response == null || response.StatusCode == HttpStatusCode.BadRequest)
return null;
if (response.StatusCode == HttpStatusCode.NotFound
|| response.StatusCode == HttpStatusCode.RequestTimeout
|| response.StatusCode == HttpStatusCode.BadGateway
|| response.StatusCode == HttpStatusCode.ServiceUnavailable)
{
throw new Exception("No Connection to Web Service");
}
var bearerData = response.Content.ReadAsStringAsync().Result;
return JObject.Parse(bearerData)["access_token"].ToString();
}
}
private void InitializeHttpClient(HttpClient client)
{
client.BaseAddress = new Uri(_webServiceAddress);
client.DefaultRequestHeaders.Accept.Clear();
client.DefaultRequestHeaders.Add("User-Agent", "Test Client");
}
private void InitializeHttpClient(HttpClient client, string token)
{
InitializeHttpClient(client);
client.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json"));
client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("bearer", token);
}
- 답변 # 1
관련 자료
- kubernetes - 5 분 후 104 연결 재설정 오류 발생
- laravel - livewirejs 연결에서 404 오류가 발생하는 이유는 무엇입니까?
- sql server - 로드가 높을 때 이상한 SQL 연결 오류가 수신 됨
- c# - 연결 풀링이있는 ADONET의 시간 초과 오류
- xaml - masterdetail 페이지 디버깅 오류 - cs0263
- python - CSV를 SQL Server로 가져 오기위한 잘못된 연결 오류 ( '08001')
- python - 이 Memgraph SSL 연결 오류를 어떻게 해결합니까?
- c++ - Visual Studio Code에서 SFML 코드를 디버깅하는 동안 오류가 발생했습니다
- openmodelica - 닫힌 볼륨 - 초기화 오류 :modelica
- 스프링 부트 및 Couchbase 연결 오류
- php - android url 연결 오류 - xampp를 사용하는 데이터베이스 연결 오류
- ibm cloud - ibm watson iot 플랫폼 - 닫힌 연결 : 작업이 승인되지 않았습니다
- c# - HttpClient 순차 호출 연결 오류
- database - 올바른 자격 증명에도 불구하고 azure sql server 연결 오류 - 오류 번호 : 18456, 상태 : 1, 클래스 : 14
- 파이썬은 연결 오류가 발생하더라도 목록을 계속 반복합니다
- python - fxcm 연결 오류 - 서버에 연결할 수 없습니다
- retrofit2 - javanetsocketexception - 연결 또는 아웃 바운드가 닫혔습니다
- sql - 이 springboot 오류를 수정하는 방법 - 연결이 설정된 후 연결 읽기 전용 모드를 적용 할 수 없습니다
- Java를 MySql에 연결할 수없는 이유는 무엇입니까 (연결 오류)?
- linux - 컵 - 네트워크 프린터 :연결 오류 : 권한이 거부되었습니다 프린터가 응답하지 않습니다
관련 질문
- c# : Visual Studio 2015 false alarm out 키워드 참조 형식을 메서드 인수로 사용
- c# : 한 줄 디버그 중단 점 어설 션 및 중단
- c# : System.IO.FileNotFoundException이 처리되지 않았습니다. 메시지 : mscorlib.dll에서 'System.IO.FileNotFoundException'형식의 처리되지 않은 예외가 발생했습니다.
- c# : Visual Studio 2015에서 WPF 디자이너가 표시되지 않음
- Visual Studio 2015에서 c# csproj를 exe로 컴파일하는 방법-오류 CS0579
- c# : StackTrace를 사용하여 조건부 중단 점을 설정하려고하면 오류가 발생합니다.
- c# : Visual Studio가 Unity에 연결할 수없는 이유는 무엇입니까?
- c# : 'Microsoft.Build.Tasks.v14.0.dll'을 찾을 수 없기 때문에 Visual Studio 2015에서 빌드 할 수 없습니다.
이것은 Windows Update KB4041083으로 인한 것 같습니다. 이 업데이트를 제거하고 모든 것이 정상적으로 작동했습니다.