-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathProgram.cs
More file actions
47 lines (36 loc) · 1.76 KB
/
Copy pathProgram.cs
File metadata and controls
47 lines (36 loc) · 1.76 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
using System;
using System.IO;
using System.Net;
namespace Billing
{
class Program
{
static void Main(string[] args)
{
String authurl = "https://login.microsoftonline.com/common/oauth2/authorize";
WebRequest myAuthRequest = WebRequest.Create(authurl);
WebResponse authRespone = myAuthRequest.GetResponse();
//String myurl = "https://management.azure.com/providers/Microsoft.Billing/enrollmentAccounts/83294316/providers/Microsoft.Consumption/usageDetails?api-version=2019-10-01";
String myurl = "https://consumption.azure.com/v3/enrollments/83294316/usagedetails/download?startTime=2020-01-01&endTime=2020-01-02";
Console.WriteLine("Enter token: ");
String token = Console.ReadLine();
WebRequest myRequest = WebRequest.Create(myurl);
//myRequest.Credentials = CredentialCache.DefaultCredentials;
myRequest.Headers.Add(HttpRequestHeader.Authorization, "Bearer " + token);
myRequest.ContentType ="application/json";
WebResponse response = myRequest.GetResponse();
Console.WriteLine(((HttpWebResponse)response).StatusDescription);
String path = @"c:\demo\consumption.json";
//FileStream myStream = File.Create(path);
StreamWriter myWriter = new StreamWriter(path);
using (Stream billingStream = response.GetResponseStream())
{
StreamReader reader = new StreamReader(billingStream);
string responseFromServer = reader.ReadToEnd();
myWriter.WriteLine(responseFromServer);
//Console.WriteLine(responseFromServer);
}
Console.WriteLine("Finished");
}
}
}