abpframework / abp

Open-source web application framework for ASP.NET Core! Offers an opinionated architecture to build enterprise software solutions with best practices on top of the .NET. Provides the fundamental infrastructure, cross-cutting-concern implementations, startup templates, application modules, UI themes, tooling and documentation.
https://abp.io
GNU Lesser General Public License v3.0
12.93k stars 3.44k forks source link

how to invoke third party api in abp service? #3439

Closed zsanhong closed 4 years ago

zsanhong commented 4 years ago

I write a service in abp application like this:

 public  async Task<StockData>PostStockInfo(StockType stockType, Dictionary<string, string> sparams, string fields = "")
        {
            string Url = "https://api.tushare.pro";
            string Token = "xxxxxxxx";
            StockPara para = new StockPara();
            para.api_name = stockType.ToString();
            para.token = Token;
            para.Params = sparams;
            para.fields = fields;

            var json = JsonConvert.SerializeObject(para);
            var data = new StringContent(json, Encoding.UTF8, "application/json");

            using (HttpResponseMessage response = await APIHelper.ApiClient.PostAsync(Url, data))
            {
                if (response.IsSuccessStatusCode)
                {
                    var msg = await response.Content.ReadAsAsync<StockAllInfo>();
                    return msg.data;

                }
                else
                {
                    throw new Exception(response.ReasonPhrase);
                }

            }
        }

if I run the same method in a winform application, I can get the right data, but if I run the service in an abp application,I got a wrong msg. I guess this is because in my api invoked an third party api, and the crossDomain is not allowed,but I don't know how to set allow crossDomain in abp? any idea? thanks a lot.

maliming commented 4 years ago

I don't see this related to Abp. You should check the error log.