public string GetAccessURL(CosRequest request) { try { CheckAppidAndRegion(request); request.CheckParameters(); StringBuilder urlBuilder = new StringBuilder(); if (request.IsHttps != null && (bool)request.IsHttps) { urlBuilder.Append("https://"); } else { urlBuilder.Append("http://"); } urlBuilder.Append(request.GetHost()); urlBuilder.Append(request.RequestPath); return(urlBuilder.ToString()); } catch (CosClientException) { throw; } catch (Exception ex) { throw new CosClientException((int)CosClientError.INVALID_ARGUMENT, ex.Message, ex); } }
private Request CreateRequest(CosRequest cosRequest) { cosRequest.CheckParameters(); string requestUrlWithSign = cosRequest.RequestURLWithSign; Request request = new Request(); request.Method = cosRequest.Method; if (requestUrlWithSign != null) { if (requestUrlWithSign.StartsWith("https")) { request.IsHttps = true; } else { request.IsHttps = false; } request.RequestUrlString = requestUrlWithSign; } else { request.IsHttps = (bool)cosRequest.IsHttps; request.Url = CreateUrl(cosRequest); request.Host = cosRequest.GetHost(); } request.UserAgent = config.UserAgnet; Dictionary <string, string> headers = cosRequest.GetRequestHeaders(); if (headers != null) { foreach (KeyValuePair <string, string> pair in headers) { request.AddHeader(pair.Key, pair.Value); } } request.Body = cosRequest.GetRequestBody(); // cacluate md5 if (CheckNeedMd5(request, cosRequest.IsNeedMD5) && request.Body != null) { request.AddHeader(CosRequestHeaderKey.CONTENT_MD5, request.Body.GetMD5()); } // content type header if (request.Body != null && request.Body.ContentType != null && !request.Headers.ContainsKey(CosRequestHeaderKey.CONTENT_TYPE)) { request.AddHeader(CosRequestHeaderKey.CONTENT_TYPE, request.Body.ContentType); } //cacluate sign, and add it. if (requestUrlWithSign == null) { CheckSign(cosRequest.GetSignSourceProvider(), request); } return(request); }