public static String RequestUploadUrl(String json) { var client = new System.Net.WebClient(); client.Headers.Add("Content-Type", "application/json"); var resp = client.UploadData(Const.UploadRequestUrl, "POST", System.Text.Encoding.UTF8.GetBytes(json)); var respStr = System.Text.Encoding.UTF8.GetString(resp); var result = SimpleJsonParser.Parse(respStr);; int status = 99; String errMsg = ""; if (result.ContainsKey("status")) { status = int.Parse(result["status"]); if (status == 0) { return(result["url"]); } } if (result.ContainsKey("errmsg")) { errMsg = result["errmsg"]; } throw new CloudException(status, errMsg); }
public static void DeleteFile(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.DeleteRequestUrl, "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()); } }
public static FileInfo QueryFile(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.QueryRequestUrl, "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"]); } // {”status”:0,”filename”:”abc.mp4”,”filekey”:”tom”, ”filesize”:1324, ”duration”:100,”servicetype”:1,”ifpublic”:0, ”url”:”servicetype=1&uid=1&fid=adsfasdfasfasfd”} FileInfo info = new FileInfo(); info.status = status; info.fileName = result.ContainsKey("filename") ? result["filename"] : ""; info.fileKey = result.ContainsKey("filekey") ? result["filekey"] : ""; info.fileSize = result.ContainsKey("filesize") ? Int64.Parse(result["filesize"]) : 0; info.duration = result.ContainsKey("duration") ? Int64.Parse(result["duration"]) : 0; info.serviceType = result.ContainsKey("servicetype") ? (ServiceType)int.Parse(result["servicetype"]) : ServiceType.Paas; info.fileType = result.ContainsKey("ifpublic") ? (FileType)int.Parse(result["ifpublic"]) : FileType.Private; info.url = result.ContainsKey("url") ? result["url"] : ""; return(info); } catch (WebException e) { throw new CloudException(99, e.ToString()); } }