# Getting error Unable to connect to the remote server when used httpclient c#

**URL:** <https://community.hubspot.com/t/getting-error-unable-to-connect-to-the-remote-server-when-used-httpclient-c/86177>\
**Category:** APIs & Integrations\
**Tags:** free\
**Created:** [July 26, 2023, 1:32pm UTC](https://community.hubspot.com/t/getting-error-unable-to-connect-to-the-remote-server-when-used-httpclient-c/86177 "2023-07-26T13:32:06Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![KMevada](https://avatars.discourse-cdn.com/v4/letter/k/258eb7/32.png) [@KMevada](https://community.hubspot.com/u/KMevada)\
**Post date:** [July 26, 2023, 1:32pm UTC](https://community.hubspot.com/t/getting-error-unable-to-connect-to-the-remote-server-when-used-httpclient-c/86177/1 "2023-07-26T13:32:06Z")

</div>

Hello,

I am calling Deal api below api request using the HTTPclient request.

[https://api.hubapi.com/deals/v1/deal/42323232](https://api.hubapi.com/deals/v1/deal/42323232)

using (var client = new HttpClient())

{

client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue(“Bearer”, “tocken”);

client.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue(“application/json”));

url = “[https://api.hubapi.com/](https://api.hubapi.com/)” + “deals/v1/deal/” + objdata.hs\_object\_id.ToString();

response = client.GetAsync(url).Result; // getting error

if (response.IsSuccessStatusCode)

{

}

}  
error details :

A connection attempt failed because the connected party did not properly respond after a period of time,  
or established connection failed because connected host has failed to respond 172.16.3.182:1251

---

<div class="post-metadata">

**Author:** ![coldrickjack](https://d10pqhm3lwygmk.cloudfront.net/user_avatar/community.hubspot.com/coldrickjack/32/6684_2.png) [@coldrickjack](https://community.hubspot.com/u/coldrickjack)\
**Post date:** [July 26, 2023, 2:17pm UTC](https://community.hubspot.com/t/getting-error-unable-to-connect-to-the-remote-server-when-used-httpclient-c/86177/2 "2023-07-26T14:17:35Z")

</div>

Hey @KMevada,

Can you try this code and see if you are getting a response?

```lia-code-sample
var client = new HttpClient();
var request = new HttpRequestMessage(HttpMethod.Get, "https://api.hubapi.com/deals/v1/deal/YOU_DEAL_ID");
request.Headers.Add("Authorization", "Bearer YOUR_TOKEN");
var response = await client.SendAsync(request);
response.EnsureSuccessStatusCode();
Console.WriteLine(await response.Content.ReadAsStringAsync());

```

Also, I’d strongly suggest using the newer v3 CRM endpoints [here](https://developers.hubspot.com/docs/api/crm/deals). From your request it appears you are using the legacy v1 endpoint [here](https://legacydocs.hubspot.com/docs/methods/deals/get_deal). Same request with updated endpoint below:

```lia-code-sample
var client = new HttpClient();
var request = new HttpRequestMessage(HttpMethod.Get, "https://api.hubapi.com/crm/v3/objects/deals/YOUR_DEAL_ID");
request.Headers.Add("Authorization", "Bearer YOUR_TOKEN");
var response = await client.SendAsync(request);
response.EnsureSuccessStatusCode();
Console.WriteLine(await response.Content.ReadAsStringAsync());

```

I’m not able to reproduce what you are seeing as the above is working for me successfully so I’m not sure if the issue lies on the HubSpot side. It could potentially be a conflict within your code base?

---

<div class="post-metadata">

**Author:** ![KMevada](https://avatars.discourse-cdn.com/v4/letter/k/258eb7/32.png) [@KMevada](https://community.hubspot.com/u/KMevada)\
**Post date:** [July 26, 2023, 3:41pm UTC](https://community.hubspot.com/t/getting-error-unable-to-connect-to-the-remote-server-when-used-httpclient-c/86177/3 "2023-07-26T15:41:02Z")

</div>

Hi @coldrickjack ,

Thank you so much for replying.

I check both url v1 and v3 and same code I used which you are provided. But still I am getting same error.

When i used same details using Postman, it’s working fine. But when i execute this in my local code debug mode. it’s returning error.
