์ผ | ์ | ํ | ์ | ๋ชฉ | ๊ธ | ํ |
---|---|---|---|---|---|---|
1 | 2 | 3 | 4 | 5 | ||
6 | 7 | 8 | 9 | 10 | 11 | 12 |
13 | 14 | 15 | 16 | 17 | 18 | 19 |
20 | 21 | 22 | 23 | 24 | 25 | 26 |
27 | 28 | 29 | 30 |
- upbit
- .csv
- Android
- ์ํธ๋ฆฌ
- swift ํ๋ฉด์ ํ
- Kakao API Address
- ASP.NET MVC
- ๋ธ๋ก์ฝ๋ฉ
- chart.js
- python
- ํ๊ธ๊นจ์ง
- ์ธ๋จธ๋ ธํธ
- league of legends
- ์์ด์ฝ๋ฉ์ต๊ด
- ์ด๋ฉ์ํ
- Excel
- AIoptimization
- MYSQL
- httpclient timeout
- ์ค๋ธ์
- largelanguagemodels
- ์ค1์ฝ๋ฉ
- cc์ฑํผ์ธ
- ์ฝ๋ฉ์ ๋ฌธ
- MSSQL
- ์ผ๋ณธ์ฌํ
- Aspose.cells
- ์คํ์์ฝ๋ฉ
- PromptEngineering
- MS-SQL
- Today
- Total
DBA
ASP.NET MVC์์ ๋ฐ์ํ๋ SocketException, IOException, WebException ๋ณธ๋ฌธ
ASP.NET MVC์์ ๋ฐ์ํ๋ SocketException, IOException, WebException
์ฝ๋ณผ 2025. 4. 10. 15:25๐งฉ ์ค๋ฅ ๋ฉ์์ง ๋ถ์ โ ์๊ฒฉ ํธ์คํธ์ ์ํด ๊ฐ์ ๋ก ์ฐ๊ฒฐ์ด ๋๊ฒผ์ต๋๋ค
ASP.NET MVC ํ๊ฒฝ์์ ์ธ๋ถ API ํธ์ถ ์ ๋ค์๊ณผ ๊ฐ์ ์๋ฌ๊ฐ ๋ฐ์ํ๋ ๊ฒฝ์ฐ๊ฐ ์์ต๋๋ค:
[SocketException (0x2746): ํ์ฌ ์ฐ๊ฒฐ์ ์๊ฒฉ ํธ์คํธ์ ์ํด ๊ฐ์ ๋ก ๋๊ฒผ์ต๋๋ค]
[IOException: ์ ์ก ์ฐ๊ฒฐ์์ ๋ฐ์ดํฐ๋ฅผ ์ฝ์ ์ ์์ต๋๋ค.]
[WebException: ๊ธฐ๋ณธ ์ฐ๊ฒฐ์ด ๋ซํ์ต๋๋ค. ๋ณด๋ด๊ธฐ์์ ์๊ธฐ์น ์์ ์ค๋ฅ๊ฐ ๋ฐ์ํ์ต๋๋ค.]
๐ ์์ธ โ API ํธ์ถ ์ ๋ณด์ ํ๋กํ ์ฝ ๋ถ์ผ์น
๋ง์ ์๋ฒ๊ฐ TLS 1.2 ์ด์๋ง ์ง์ํ๋ฉฐ, ASP.NET ํ๋ก์ ํธ๊ฐ ์ด๋ฅผ ์ง์ํ์ง ์์ผ๋ฉด ์ฐ๊ฒฐ์ด ๋์ด์ง๋๋ค.
๐ง ํด๊ฒฐ ๋ฐฉ๋ฒ โ ServicePointManager๋ฅผ ํตํ TLS ์ค์
๐ Global.asax.cs์์ TLS ์ค์ ์ ์ฉํ๊ธฐ
csharp
protected void Application_Start()
{
System.Net.ServicePointManager.SecurityProtocol =
SecurityProtocolType.Tls12 |
SecurityProtocolType.Tls11 |
SecurityProtocolType.Tls;
// ๊ธฐํ ์ด๊ธฐํ ์ฝ๋
}
๐ Controller์์ TLS ์ค์ ์ ์ฉํ๊ธฐ
csharp
public async Task<ActionResult> Login(string loginID, string loginPWD)
{
ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls12 | SecurityProtocolType.Tls11 | SecurityProtocolType.Tls;
var loginData = new LoginRequest
{
.....
};
//using (var client = new HttpClient())
//ํ์์์ ์ถ๊ฐ
using (var client = new HttpClient() { Timeout = TimeSpan.FromSeconds(30)})
{
.....
}
}
๐ Web.config์์ ํ์์์๋ ํจ๊ป ๊ณ ๋ คํ์ธ์ API ํต์ ์ค๋ฅ๋ ์ฐ๊ฒฐ ์๊ฐ ์ด๊ณผ์ผ ์๋ ์์ต๋๋ค. ํจ๊ป ์ ๊ฒํด ์ฃผ์ธ์.
๐งฉ ์ถ๊ฐ ํ โ ์์ ์ ์ธ API ํต์ ์ ์ํ ์ฒดํฌ๋ฆฌ์คํธ
- .NET ๋ฒ์ ์ ๊ทธ๋ ์ด๋
- ์ธ๋ถ ์๋ฒ TLS ์ง์ ํ์ธ
- ์์ธ ๋ก๊น
โ ๊ฒฐ๋ก โ ์ค๋ฅ๋ฅผ ์๋ฐฉํ๋ ๋ณด์ ์ค์ ์ ์ค์์ฑ ๊ฐ๋จํ TLS ์ค์ ๋ง์ผ๋ก๋ API ํต์ ์ค๋ฅ๋ฅผ ์๋ฐฉํ ์ ์์ต๋๋ค. ํนํ ServicePointManager ์ค์ ์ ํตํด ์ ๋ขฐ๋ ๋์ ํต์ ํ๊ฒฝ์ ๊ตฌ์ถํ์ธ์!