Sharpen.HttpURLConnection.SetRequestProperty C# (CSharp) Method

SetRequestProperty() public method

public SetRequestProperty ( string key, string value ) : void
key string
value string
return void
        public void SetRequestProperty(string key, string value)
        {
            switch (key.ToLower ()) {
            case "user-agent": request.UserAgent = value; break;
            case "content-length": request.ContentLength = long.Parse (value); break;
            case "content-type": request.ContentType = value; break;
            case "expect": request.Expect = value; break;
            case "referer": request.Referer = value; break;
            case "transfer-encoding": request.TransferEncoding = value; break;
            case "accept": request.Accept = value; break;
            default: request.Headers.Set (key, value); break;
            }
        }

Usage Example

Example #1
0
		/// <exception cref="System.IO.IOException"></exception>
		private void Authorize(HttpURLConnection c)
		{
			IDictionary<string, IList<string>> reqHdr = c.GetRequestProperties();
			SortedDictionary<string, string> sigHdr = new SortedDictionary<string, string>();
			foreach (KeyValuePair<string, IList<string>> entry in reqHdr.EntrySet())
			{
				string hdr = entry.Key;
				if (IsSignedHeader(hdr))
				{
					sigHdr.Put(StringUtils.ToLowerCase(hdr), ToCleanString(entry.Value));
				}
			}
			StringBuilder s = new StringBuilder();
			s.Append(c.GetRequestMethod());
			s.Append('\n');
			s.Append(Remove(sigHdr, "content-md5"));
			s.Append('\n');
			s.Append(Remove(sigHdr, "content-type"));
			s.Append('\n');
			s.Append(Remove(sigHdr, "date"));
			s.Append('\n');
			foreach (KeyValuePair<string, string> e in sigHdr.EntrySet())
			{
				s.Append(e.Key);
				s.Append(':');
				s.Append(e.Value);
				s.Append('\n');
			}
			string host = c.GetURL().GetHost();
			s.Append('/');
			s.Append(Sharpen.Runtime.Substring(host, 0, host.Length - DOMAIN.Length - 1));
			s.Append(c.GetURL().AbsolutePath);
			string sec;
			try
			{
				Mac m = Mac.GetInstance(HMAC);
				m.Init(privateKey);
				sec = Base64.EncodeBytes(m.DoFinal(Sharpen.Runtime.GetBytesForString(s.ToString()
					, "UTF-8")));
			}
			catch (NoSuchAlgorithmException e_1)
			{
				throw new IOException(MessageFormat.Format(JGitText.Get().noHMACsupport, HMAC, e_1
					.Message));
			}
			catch (InvalidKeyException e_1)
			{
				throw new IOException(MessageFormat.Format(JGitText.Get().invalidKey, e_1.Message
					));
			}
			c.SetRequestProperty("Authorization", "AWS " + publicKey + ":" + sec);
		}
All Usage Examples Of Sharpen.HttpURLConnection::SetRequestProperty