[英]Can't access Public API with C# HttpClient
我正在嘗試通過 C# 從 Etoro(交易應用程序)向公共 API 發出請求。 如果我在瀏覽器中調用 URI 一切正常。 例如: https://www.etoro.com/sapi/trade-data-real/live/public/portfolios?format=json&cid=3180395&client_request_id=8ae032db-7642-4b48-9628-b635a29aefba
但是如果我運行我的程序,有時它可以工作,但大多數時候我得到一個“錯誤 512”。
System.Net.Http.HttpRequestException: "Der Antwortstatuscode gibt keinen Erfolg an: 512 (Unknown Code)."
我的代碼中是否有錯誤,或者是用戶代理的問題,還是其他問題? 有任何想法嗎?
{
using System.Net.Http;
using System.Net.Http.Headers;
using System.Threading.Tasks;
namespace cUrl
{
class Program
{
public static string responseBody { get; set; }
static async Task Main(string[] args)
{
Guid uuid = Guid.NewGuid();
var client = new HttpClient();
client.BaseAddress = new Uri("https://www.etoro.com/sapi/trade-data-real/live/public/portfolios?format=json&cid=3180395" + "&client_request_id=" + uuid);
client.DefaultRequestHeaders.Accept.Clear();
client.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json"));
responseBody = await client.GetStringAsync(client.BaseAddress);
Console.WriteLine(responseBody);
Console.ReadLine();
}
}
}
我使用瀏覽器或 Postman 嘗試過,有時我得到了結果,有時是錯誤
"error":{"failureReason":"Something went wrong, please try again"}
所以我認為這是 API 的問題,而不是客戶端的問題。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.