Esempio n. 1
0
 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);
     }
 }
Esempio n. 2
0
        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);
        }
Esempio n. 3
0
        private HttpUrl CreateUrl(CosRequest cosRequest)
        {
            HttpUrl httpUrl = new HttpUrl();

            httpUrl.Scheme(cosRequest.IsHttps ? "https" : "http");
            httpUrl.Host(cosRequest.GetHost());
            httpUrl.SetPath(cosRequest.RequestPath);
            httpUrl.SetQueryParamters(cosRequest.GetRequestParamters());
            return(httpUrl);
        }
Esempio n. 4
0
        private HttpUrl CreateUrl(CosRequest cosRequest)
        {
            HttpUrl httpUrl = new HttpUrl();

            httpUrl.Scheme = (bool)cosRequest.IsHttps ? "https" : "http";
            httpUrl.Host   = cosRequest.GetHost();
            httpUrl.Path   = URLEncodeUtils.EncodePathOfURL(cosRequest.RequestPath);
            httpUrl.SetQueryParameters(cosRequest.GetRequestParamters());
            return(httpUrl);
        }