|
3 | 3 | using Qiniu.Http; |
4 | 4 | using Qiniu.Util; |
5 | 5 | using System.Collections.Generic; |
| 6 | +using System.Collections.Specialized; |
| 7 | + |
6 | 8 | namespace Qiniu.Storage |
7 | 9 | { |
8 | 10 | /// <summary> |
@@ -43,9 +45,13 @@ public StatResult Stat(string bucket, string key) |
43 | 45 | { |
44 | 46 | string statUrl = string.Format("{0}{1}", this.config.RsHost(this.mac.AccessKey, bucket), |
45 | 47 | StatOp(bucket, key)); |
46 | | - string token = auth.CreateManageToken(statUrl); |
| 48 | + StringDictionary headers = new StringDictionary |
| 49 | + { |
| 50 | + {"Content-Type", ContentType.WWW_FORM_URLENC} |
| 51 | + }; |
| 52 | + string token = auth.CreateManageTokenV2("GET", statUrl, headers); |
47 | 53 |
|
48 | | - HttpResult hr = httpManager.Get(statUrl, token); |
| 54 | + HttpResult hr = httpManager.Get(statUrl, headers, token); |
49 | 55 | result.Shadow(hr); |
50 | 56 | } |
51 | 57 | catch (QiniuException ex) |
@@ -88,9 +94,13 @@ public BucketsResult Buckets(bool shared) |
88 | 94 | sharedStr = "true"; |
89 | 95 | } |
90 | 96 | string bucketsUrl = string.Format("{0}/buckets?shared={1}", rsHost, sharedStr); |
91 | | - string token = auth.CreateManageToken(bucketsUrl); |
| 97 | + StringDictionary headers = new StringDictionary |
| 98 | + { |
| 99 | + {"Content-Type", ContentType.WWW_FORM_URLENC} |
| 100 | + }; |
| 101 | + string token = auth.CreateManageTokenV2("GET", bucketsUrl, headers); |
92 | 102 |
|
93 | | - HttpResult hr = httpManager.Get(bucketsUrl, token); |
| 103 | + HttpResult hr = httpManager.Get(bucketsUrl, headers, token); |
94 | 104 | result.Shadow(hr); |
95 | 105 | } |
96 | 106 | catch (QiniuException ex) |
@@ -129,9 +139,13 @@ public HttpResult Delete(string bucket, string key) |
129 | 139 | { |
130 | 140 | string deleteUrl = string.Format("{0}{1}", this.config.RsHost(this.mac.AccessKey, bucket), |
131 | 141 | DeleteOp(bucket, key)); |
132 | | - string token = auth.CreateManageToken(deleteUrl); |
| 142 | + StringDictionary headers = new StringDictionary |
| 143 | + { |
| 144 | + {"Content-Type", ContentType.WWW_FORM_URLENC} |
| 145 | + }; |
| 146 | + string token = auth.CreateManageTokenV2("POST", deleteUrl, headers); |
133 | 147 |
|
134 | | - result = httpManager.Post(deleteUrl, token); |
| 148 | + result = httpManager.Post(deleteUrl, headers, token); |
135 | 149 | } |
136 | 150 | catch (QiniuException ex) |
137 | 151 | { |
@@ -184,9 +198,13 @@ public HttpResult Copy(string srcBucket, string srcKey, string dstBucket, string |
184 | 198 | { |
185 | 199 | string copyUrl = string.Format("{0}{1}", this.config.RsHost(this.mac.AccessKey, srcBucket), |
186 | 200 | CopyOp(srcBucket, srcKey, dstBucket, dstKey, force)); |
187 | | - string token = auth.CreateManageToken(copyUrl); |
| 201 | + StringDictionary headers = new StringDictionary |
| 202 | + { |
| 203 | + {"Content-Type", ContentType.WWW_FORM_URLENC} |
| 204 | + }; |
| 205 | + string token = auth.CreateManageTokenV2("POST", copyUrl, headers); |
188 | 206 |
|
189 | | - result = httpManager.Post(copyUrl, token); |
| 207 | + result = httpManager.Post(copyUrl, headers, token); |
190 | 208 | } |
191 | 209 | catch (QiniuException ex) |
192 | 210 | { |
@@ -239,9 +257,13 @@ public HttpResult Move(string srcBucket, string srcKey, string dstBucket, string |
239 | 257 | { |
240 | 258 | string moveUrl = string.Format("{0}{1}", this.config.RsHost(this.mac.AccessKey, srcBucket), |
241 | 259 | MoveOp(srcBucket, srcKey, dstBucket, dstKey, force)); |
242 | | - string token = auth.CreateManageToken(moveUrl); |
| 260 | + StringDictionary headers = new StringDictionary |
| 261 | + { |
| 262 | + {"Content-Type", ContentType.WWW_FORM_URLENC} |
| 263 | + }; |
| 264 | + string token = auth.CreateManageTokenV2("POST", moveUrl, headers); |
243 | 265 |
|
244 | | - result = httpManager.Post(moveUrl, token); |
| 266 | + result = httpManager.Post(moveUrl, headers, token); |
245 | 267 | } |
246 | 268 | catch (QiniuException ex) |
247 | 269 | { |
@@ -279,8 +301,12 @@ public HttpResult ChangeMime(string bucket, string key, string mimeType) |
279 | 301 | { |
280 | 302 | string chgmUrl = string.Format("{0}{1}", this.config.RsHost(this.mac.AccessKey, bucket), |
281 | 303 | ChangeMimeOp(bucket, key, mimeType)); |
282 | | - string token = auth.CreateManageToken(chgmUrl); |
283 | | - result = httpManager.Post(chgmUrl, token); |
| 304 | + StringDictionary headers = new StringDictionary |
| 305 | + { |
| 306 | + {"Content-Type", ContentType.WWW_FORM_URLENC} |
| 307 | + }; |
| 308 | + string token = auth.CreateManageTokenV2("POST", chgmUrl, headers); |
| 309 | + result = httpManager.Post(chgmUrl, headers, token); |
284 | 310 | } |
285 | 311 | catch (QiniuException ex) |
286 | 312 | { |
@@ -318,8 +344,12 @@ public HttpResult ChangeType(string bucket, string key, int fileType) |
318 | 344 | { |
319 | 345 | string chtypeUrl = string.Format("{0}{1}", this.config.RsHost(this.mac.AccessKey, bucket), |
320 | 346 | ChangeTypeOp(bucket, key, fileType)); |
321 | | - string token = auth.CreateManageToken(chtypeUrl); |
322 | | - result = httpManager.Post(chtypeUrl, token); |
| 347 | + StringDictionary headers = new StringDictionary |
| 348 | + { |
| 349 | + {"Content-Type", ContentType.WWW_FORM_URLENC} |
| 350 | + }; |
| 351 | + string token = auth.CreateManageTokenV2("POST", chtypeUrl, headers); |
| 352 | + result = httpManager.Post(chtypeUrl, headers, token); |
323 | 353 | } |
324 | 354 | catch (QiniuException ex) |
325 | 355 | { |
@@ -351,8 +381,12 @@ public HttpResult RestoreAr(string bucket, string key, int freezeAfterDays) |
351 | 381 | string restoreUrl = string.Format("{0}{1}", |
352 | 382 | this.config.RsHost(this.mac.AccessKey, bucket), |
353 | 383 | RestoreArOp(bucket, key, freezeAfterDays)); |
354 | | - string token = auth.CreateManageToken(restoreUrl); |
355 | | - result = httpManager.Post(restoreUrl, token); |
| 384 | + StringDictionary headers = new StringDictionary |
| 385 | + { |
| 386 | + {"Content-Type", ContentType.WWW_FORM_URLENC} |
| 387 | + }; |
| 388 | + string token = auth.CreateManageTokenV2("POST", restoreUrl, headers); |
| 389 | + result = httpManager.Post(restoreUrl, headers, token); |
356 | 390 | } |
357 | 391 | catch (QiniuException ex) |
358 | 392 | { |
@@ -389,8 +423,15 @@ private BatchResult Batch(string batchOps) |
389 | 423 | string scheme = this.config.UseHttps ? "https://" : "http://"; |
390 | 424 | string rsHost = string.Format("{0}{1}", scheme, Config.DefaultRsHost); |
391 | 425 | string batchUrl = rsHost + "/batch"; |
| 426 | + string token = auth.CreateManageTokenV2( |
| 427 | + "POST", |
| 428 | + batchUrl, |
| 429 | + new StringDictionary |
| 430 | + { |
| 431 | + {"Content-Type", ContentType.WWW_FORM_URLENC} |
| 432 | + }, |
| 433 | + batchOps); |
392 | 434 | byte[] data = Encoding.UTF8.GetBytes(batchOps); |
393 | | - string token = auth.CreateManageToken(batchUrl, data); |
394 | 435 |
|
395 | 436 | HttpResult hr = httpManager.PostForm(batchUrl, data, token); |
396 | 437 | result.Shadow(hr); |
@@ -448,9 +489,13 @@ public FetchResult Fetch(string resUrl, string bucket, string key) |
448 | 489 | { |
449 | 490 | string fetchUrl = string.Format("{0}{1}", this.config.IovipHost(this.mac.AccessKey, bucket), |
450 | 491 | FetchOp(resUrl, bucket, key)); |
451 | | - string token = auth.CreateManageToken(fetchUrl); |
| 492 | + StringDictionary headers = new StringDictionary |
| 493 | + { |
| 494 | + {"Content-Type", ContentType.WWW_FORM_URLENC} |
| 495 | + }; |
| 496 | + string token = auth.CreateManageTokenV2("POST", fetchUrl, headers); |
452 | 497 |
|
453 | | - HttpResult httpResult = httpManager.Post(fetchUrl, token); |
| 498 | + HttpResult httpResult = httpManager.Post(fetchUrl, headers, token); |
454 | 499 | result.Shadow(httpResult); |
455 | 500 | } |
456 | 501 | catch (QiniuException ex) |
@@ -487,9 +532,13 @@ public HttpResult Prefetch(string bucket, string key) |
487 | 532 | try |
488 | 533 | { |
489 | 534 | string prefetchUrl = this.config.IovipHost(this.mac.AccessKey, bucket) + PrefetchOp(bucket, key); |
490 | | - string token = auth.CreateManageToken(prefetchUrl); |
| 535 | + StringDictionary headers = new StringDictionary |
| 536 | + { |
| 537 | + {"Content-Type", ContentType.WWW_FORM_URLENC} |
| 538 | + }; |
| 539 | + string token = auth.CreateManageTokenV2("POST", prefetchUrl, headers); |
491 | 540 |
|
492 | | - result = httpManager.Post(prefetchUrl, token); |
| 541 | + result = httpManager.Post(prefetchUrl, headers, token); |
493 | 542 | } |
494 | 543 | catch (QiniuException ex) |
495 | 544 | { |
@@ -527,8 +576,15 @@ public DomainsResult Domains(string bucket) |
527 | 576 | string rsHost = string.Format("{0}{1}", scheme, Config.DefaultApiHost); |
528 | 577 | string domainsUrl = string.Format("{0}{1}", rsHost, "/v6/domain/list"); |
529 | 578 | string body = string.Format("tbl={0}", bucket); |
| 579 | + string token = auth.CreateManageTokenV2( |
| 580 | + "POST", |
| 581 | + domainsUrl, |
| 582 | + new StringDictionary |
| 583 | + { |
| 584 | + {"Content-Type", ContentType.WWW_FORM_URLENC} |
| 585 | + }, |
| 586 | + body); |
530 | 587 | byte[] data = Encoding.UTF8.GetBytes(body); |
531 | | - string token = auth.CreateManageToken(domainsUrl, data); |
532 | 588 |
|
533 | 589 | HttpResult hr = httpManager.PostForm(domainsUrl, data, token); |
534 | 590 | result.Shadow(hr); |
@@ -615,9 +671,13 @@ public ListResult ListFiles(string bucket, string prefix, string marker, int lim |
615 | 671 | } |
616 | 672 |
|
617 | 673 | string listUrl = string.Format("{0}{1}", this.config.RsfHost(this.mac.AccessKey, bucket), sb.ToString()); |
618 | | - string token = auth.CreateManageToken(listUrl); |
| 674 | + StringDictionary headers = new StringDictionary |
| 675 | + { |
| 676 | + {"Content-Type", ContentType.WWW_FORM_URLENC} |
| 677 | + }; |
| 678 | + string token = auth.CreateManageTokenV2("POST", listUrl, headers); |
619 | 679 |
|
620 | | - HttpResult hr = httpManager.Post(listUrl, token); |
| 680 | + HttpResult hr = httpManager.Post(listUrl, headers, token); |
621 | 681 | result.Shadow(hr); |
622 | 682 | } |
623 | 683 | catch (QiniuException ex) |
@@ -656,8 +716,12 @@ public HttpResult DeleteAfterDays(string bucket, string key, int deleteAfterDays |
656 | 716 | { |
657 | 717 | string updateUrl = string.Format("{0}{1}", this.config.RsHost(this.mac.AccessKey, bucket), |
658 | 718 | DeleteAfterDaysOp(bucket, key, deleteAfterDays)); |
659 | | - string token = auth.CreateManageToken(updateUrl); |
660 | | - result = httpManager.Post(updateUrl, token); |
| 719 | + StringDictionary headers = new StringDictionary |
| 720 | + { |
| 721 | + {"Content-Type", ContentType.WWW_FORM_URLENC} |
| 722 | + }; |
| 723 | + string token = auth.CreateManageTokenV2("POST", updateUrl, headers); |
| 724 | + result = httpManager.Post(updateUrl, headers, token); |
661 | 725 | } |
662 | 726 | catch (QiniuException ex) |
663 | 727 | { |
|
0 commit comments