Tried to create new Postgres database in google cloud SQL through C# console application ,but its throwing 401 unauthorized issue.
How to pass Api key or any authorization header for google cloud api's?
private static async void CreateDb() { var myObject = new { name = "test-google-api", }; var json = JsonConvert.SerializeObject(myObject); var data = new StringContent(json, Encoding.UTF8, "application/json"); var url = "https://www.googleapis.com/sql/v1beta4/projects/{projectid}/instances/{instanceid}/databases"; using var client = new HttpClient(); var response = await client.PostAsync(url, data).ConfigureAwait(false); string result = response.Content.ReadAsStringAsync().Result; Console.WriteLine(result); }
async voidunless its an event handler, also don't callResulton an async method (basically ever) or you will be back here with other problems before you know itAuthorization: Bearer <TOKEN>header. While learning use the token generated by this command: cloud.google.com/sdk/gcloud/reference/auth/application-default/…