/// <summary> /// 批处理 /// </summary> /// <param name="batchOps">批量操作的操作字符串</param> /// <returns>状态码为200时表示OK</returns> private BatchResult Batch(string batchOps) { BatchResult result = new BatchResult(); try { string scheme = this.config.UseHttps ? "https://" : "http://"; string rsHost = string.Format("{0}{1}", scheme, Config.DefaultRsHost); string batchUrl = rsHost + "/batch"; byte[] data = Encoding.UTF8.GetBytes(batchOps); string token = auth.CreateManageToken(batchUrl, data); HttpResult hr = httpManager.PostForm(batchUrl, data, token); result.Shadow(hr); } catch (QiniuException ex) { StringBuilder sb = new StringBuilder(); sb.AppendFormat("[{0}] [batch] Error: ", DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss.ffff")); Exception e = ex; while (e != null) { sb.Append(e.Message + " "); e = e.InnerException; } sb.AppendLine(); result.Code = ex.HttpResult.Code; result.RefCode = ex.HttpResult.Code; result.Text = ex.HttpResult.Text; result.RefText += sb.ToString(); } return(result); }
/// <summary> /// 批处理 /// </summary> /// <param name="batchOps">批量操作的操作字符串</param> /// <returns>状态码为200时表示OK</returns> private async Task <BatchResult> Batch(string batchOps) { var result = new BatchResult(); try { var scheme = _config.UseHttps ? "https://" : "http://"; var rsHost = $"{scheme}{Config.DefaultRsHost}"; var batchUrl = rsHost + "/batch"; var data = Encoding.UTF8.GetBytes(batchOps); var token = _auth.CreateManageToken(batchUrl, data); var hr = await _httpManager.PostFormAsync(batchUrl, data, token); result.Shadow(hr); } catch (QiniuException ex) { var sb = new StringBuilder(); sb.Append($"[{DateTime.Now:yyyy-MM-dd HH:mm:ss.ffff}] [batch] Error: "); Exception e = ex; while (e != null) { sb.Append(e.Message + " "); e = e.InnerException; } sb.AppendLine(); result.Code = ex.HttpResult.Code; result.RefCode = ex.HttpResult.Code; result.Text = ex.HttpResult.Text; result.RefText += sb.ToString(); } return(result); }