-
Notifications
You must be signed in to change notification settings - Fork 0
/
AzureSample01.cs
86 lines (78 loc) · 2.97 KB
/
AzureSample01.cs
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
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
using System.Collections;
using System.Collections.Generic;
using System.Security.Cryptography.X509Certificates;
using UnityEngine;
using UnityEngine.UI;
public class AzureSample01 : MonoBehaviour
{
/// <summary>
/// Mono が HTTPS 接続でエラーを出すので、事前に回避できるようにするコールバック
/// </summary>
/// <param name="sender"></param>
/// <param name="certificate"></param>
/// <param name="chain"></param>
/// <param name="policyErrors"></param>
/// <returns></returns>
private static bool ValidateRemoteCertificate(
object sender,
X509Certificate certificate,
X509Chain chain,
System.Net.Security.SslPolicyErrors policyErrors
)
{
if (policyErrors == System.Net.Security.SslPolicyErrors.RemoteCertificateChainErrors)
{
if (certificate.Subject == "CN=*.azurewebsites.net")
return true;
else if (certificate.Subject == "CN=*.blob.core.windows.net")
return true;
else if (certificate.Subject == "CN=*.table.core.windows.net")
return true;
else if (certificate.Subject == "CN=*.documents.azure.com")
return true;
else if (certificate.Subject.StartsWith("CN=localhost"))
return true;
}
else if (policyErrors == System.Net.Security.SslPolicyErrors.None)
{
return true;
}
return false;
}
// Start is called before the first frame update
void Start()
{
// Mono が HTTPS 接続でエラーを出すので、事前に回避できるようにするコールバック
System.Net.ServicePointManager.ServerCertificateValidationCallback += ValidateRemoteCertificate;
GetDoIt();
}
// Update is called once per frame
void Update()
{
}
/// <summary>
/// 処理
/// </summary>
public bool GetDoIt()
{
int serverIndex = 0;
string addHeader = "x-chigusa-serverid:" + serverIndex;
addHeader += "\n" + "x-chigusa-userid:" + "DammyId";
addHeader += "\n" + "x-chigusa-appversion:" + Chigusa.AzureHelper.ApiAppREST.ChigusaVersion;
var apiApp = new Chigusa.AzureHelper.ApiApp(serverIndex);
var request = apiApp.BuildBaseRequest("GET", "values", "accountName", addHeader);
request.Headers.Add("x-chigusa-serverid", serverIndex.ToString());
request.Headers.Add("x-chigusa-userid", "DammyId");
request.Headers.Add("x-chigusa-appversion", Chigusa.AzureHelper.ApiAppREST.ChigusaVersion);
using (var res = request.GetResponse() as System.Net.HttpWebResponse)
{
if (res.StatusCode != System.Net.HttpStatusCode.OK)
return false;
var sr = new System.IO.StreamReader(res.GetResponseStream());
var con = sr.ReadToEnd();
sr.Close();
Debug.Log(con);
}
return true;
}
}