admin管理员组文章数量:1316030
Has anyone successfully connected to the IBKR Web API V1.0 using C#? Any working sample or insights into why this might be happening would be greatly appreciated. (PS: I am not asking about TWS or IBGateWay)
I have successfully connected to the IBKR Web API V1.0 Gateway using Postman, following the official documentation. As you see in the following picture, no authorization or additional headers were required in Postman:
However, when I attempt to make the same request in a C# console application, I receive the following error:
Error 403 - Access Denied
.
I couldn't find a single working C# example for this API, most of the available samples are in Python. I tried mimicking the Python code (for example) in C#, but I still get the same error.
This is my simple Console application for the same Postman call:
static async Task Main()
{
HttpClientHandler handler = new HttpClientHandler();
handler.ServerCertificateCustomValidationCallback = (message, cert, chain, errors) => true;
HttpClient client = new HttpClient(handler);
client.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json"));
HttpResponseMessage response = await client.GetAsync("https://localhost:5000/v1/api/iserver/auth/status");
string res = await response.Content.ReadAsStringAsync();
Console.WriteLine(res);
}
Has anyone successfully connected to the IBKR Web API V1.0 using C#? Any working sample or insights into why this might be happening would be greatly appreciated. (PS: I am not asking about TWS or IBGateWay)
I have successfully connected to the IBKR Web API V1.0 Gateway using Postman, following the official documentation. As you see in the following picture, no authorization or additional headers were required in Postman:
However, when I attempt to make the same request in a C# console application, I receive the following error:
Error 403 - Access Denied
.
I couldn't find a single working C# example for this API, most of the available samples are in Python. I tried mimicking the Python code (for example) in C#, but I still get the same error.
This is my simple Console application for the same Postman call:
static async Task Main()
{
HttpClientHandler handler = new HttpClientHandler();
handler.ServerCertificateCustomValidationCallback = (message, cert, chain, errors) => true;
HttpClient client = new HttpClient(handler);
client.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json"));
HttpResponseMessage response = await client.GetAsync("https://localhost:5000/v1/api/iserver/auth/status");
string res = await response.Content.ReadAsStringAsync();
Console.WriteLine(res);
}
Share
Improve this question
edited Jan 30 at 7:28
VLAZ
29.1k9 gold badges63 silver badges84 bronze badges
asked Jan 30 at 4:59
Sharif YazdianSharif Yazdian
4,7484 gold badges23 silver badges25 bronze badges
1 Answer
Reset to default 1Found that I have to add this header to the C# API call:
request.Headers.Add("User-Agent", "Mozilla/5.0 (Windows NT 10.0; Win64; x64) Chrome/120.0.0.0 Safari/537.36");
So the working code is:
static async Task Main()
{
HttpClientHandler handler = new HttpClientHandler();
handler.ServerCertificateCustomValidationCallback = (message, cert, chain, errors) => true;
HttpClient client = new HttpClient(handler);
client.DefaultRequestHeaders.Add("User-Agent", "Mozilla/5.0 (Windows NT 10.0; Win64; x64) Chrome/120.0.0.0 Safari/537.36");
HttpResponseMessage response = await client.GetAsync("https://localhost:5000/v1/api/iserver/auth/status");
string res = await response.Content.ReadAsStringAsync();
Console.WriteLine(res);
}
There is no documentation for Ibrk C# Api.
本文标签: cTrouble Connecting to IBKR Web API V10 (403 Error)Stack Overflow
版权声明:本文标题:c# - Trouble Connecting to IBKR Web API V1.0 (403 Error) - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1741985252a2408637.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论