远程服务器返回错误:(400)错误的请求。使用Firebase服务

时间:2019-04-04 19:53:36

标签: c# firebase firebase-dynamic-links

我遇到错误远程服务器返回错误:(400)运行以下代码时请求错误。我正在尝试使用Firebase动态链接将我的Long Url转换为Short Url。请建议我如何解决此问题,或者如果我在任何地方错了,都建议我。谢谢

public string BitlyURLShort(string longUrl)
    {
        string shorturl;
        try
        {
            string GoogleAPIkey = "MyAPI";
            var url = string.Format("https://firebasedynamiclinks.googleapis.com/v1/shortLinks?key=" + GoogleAPIkey);
            HttpWebRequest httpWebRequest = (HttpWebRequest)WebRequest.Create(url);
            httpWebRequest.ContentType = "application/json";
            httpWebRequest.Method = "POST";
            longurl = "http://www.google.com";

            using (var streamWriter = new StreamWriter(httpWebRequest.GetRequestStream()))
            {
                string json = "{\"longDynamicLink\":\"" + HttpUtility.UrlEncode("http://www.google.com", Encoding.UTF8) + "\"}";
                streamWriter.Write(json);
            }

            var httpResponse = (HttpWebResponse)httpWebRequest.GetResponse();
            using (var streamReader = new StreamReader(httpResponse.GetResponseStream()))
            {
                var responseText = streamReader.ReadToEnd();
                dynamic data = JObject.Parse(responseText);
                shorturl = data.id;
            }

            Console.WriteLine("This is the short URL:" + shorturl);
        }
        catch (Exception a)
        {
            throw;
        }
        return shorturl;
    }```

0 个答案:

没有答案