创建Fire Base动态链接时出现错误的请求错误

时间:2019-03-25 20:22:11

标签: firebase firebase-dynamic-links

我正在从dotnet核心控制台应用程序创建firebase动态链接。我可以创建frm postman链接,但是当我从C#代码发送请求时,它会抛出错误的请求错误。我的代码如下

 using (var httpClient = new FireBaseHttpClient(_fireBaseClientConfiguration).Create().Result)
        {
            var path = FireBaseApiRoutes.Shorten.Replace(@"{apiVersion}", _fireBaseClientConfiguration.Value.ApiVersion).Replace(@"{apiKey}", _fireBaseClientConfiguration.Value.ApiKey);

            var request = new FireBaseDynamicLinkRequest()
            {
                longDynamicLink = FireBaseApiConstants.DynamicLinkFormat.Replace(@"{appLink}", _fireBaseClientConfiguration.Value.AppLink).Replace(@"{requestUrl}", HttpUtility.UrlEncode(requestUrl, Encoding.UTF8)),
                suffix = new Suffix() { option = "UNGUESSABLE" }
            };
            var response = await httpClient.PostAsJsonAsync(path, request);

            if (response.IsSuccessStatusCode)
            {
                FireBaseDynamicLinkResponse fbResponse = await response.Content.ReadAsAsync<FireBaseDynamicLinkResponse>();
                return new ShortLinkResponse() { LongUrl = requestUrl, ShortUrl = fbResponse.shortLink };
            }
            else
                return null;
        }

创建方法如下

  var client = new HttpClient();
        client.BaseAddress = new Uri(_fireBaseClientConfiguration.Value.BaseUrl);
        client.DefaultRequestHeaders.Accept.Clear();
        client.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json"));
        //client.DefaultRequestHeaders.TryAddWithoutValidation("Content-Type", "application/json; charset=utf-8");
        return await Task.Run(() => client);

没有关于此错误的其他信息,因此与此相关的任何指导都将真正有帮助。

0 个答案:

没有答案