-
Notifications
You must be signed in to change notification settings - Fork 1
/
Update.cs
53 lines (40 loc) · 1.54 KB
/
Update.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
using System;
using System.Net;
using System.Collections.Generic;
using System.Text;
namespace Baofeng.Cloud {
public class Update {
public static void UpdateFile(Profile profile, Baofeng.Cloud.ServiceType serviceType,
String fileName, String fileKey, FileType fileType) {
String token = Token.CreateUpdateToken(profile.accessKey,
profile.secretKey,
serviceType,
fileType,
fileName,
fileKey
);
UpdateFile(token);
}
public static void UpdateFile(String token) {
try {
String json = "{\"token\":\"" + token + "\"}";
var client = new System.Net.WebClient();
client.Headers.Add("Content-Type", "application/json");
var resp = client.UploadData(Const.UpdateRequestUrl, "POST",
System.Text.Encoding.UTF8.GetBytes(json));
var respStr = System.Text.Encoding.UTF8.GetString(resp);
var result = SimpleJsonParser.Parse(respStr); ;
int status = 99;
if (result.ContainsKey("status")) {
status = int.Parse(result["status"]);
if (status == 0) {
return;
}
}
throw new CloudException(status, "");
} catch (WebException e) {
throw new CloudException(99, e.ToString());
}
}
}
}