FlickrNet.FlickrResponder.OAuthCalculateAuthHeader C# (CSharp) Méthode

OAuthCalculateAuthHeader() public static méthode

Returns the string for the Authorisation header to be used for OAuth authentication. Parameters other than OAuth ones are ignored.
public static OAuthCalculateAuthHeader ( string>.Dictionary parameters ) : string
parameters string>.Dictionary OAuth and other parameters.
Résultat string
        public static string OAuthCalculateAuthHeader(Dictionary<string, string> parameters)
        {
            StringBuilder sb = new StringBuilder("OAuth ");
            foreach (KeyValuePair<string, string> pair in parameters)
            {
                if (pair.Key.StartsWith("oauth"))
                {
                    sb.Append(pair.Key + "=\"" + Uri.EscapeDataString(pair.Value) + "\",");
                }
            }

            return sb.Remove(sb.Length - 1, 1).ToString();
        }

Usage Example

Exemple #1
0
        private string UploadData(Stream imageStream, string fileName, Uri uploadUri, Dictionary <string, string> parameters)
        {
            string boundary = "FLICKR_MIME_" + DateTime.Now.ToString("yyyyMMddhhmmss", System.Globalization.DateTimeFormatInfo.InvariantInfo);

            string authHeader = FlickrResponder.OAuthCalculateAuthHeader(parameters);

            byte[] dataBuffer = CreateUploadData(imageStream, fileName, parameters, boundary);

            HttpWebRequest req = (HttpWebRequest)HttpWebRequest.Create(uploadUri);

            //req.UserAgent = "Mozilla/4.0 FlickrNet API (compatible; MSIE 6.0; Windows NT 5.1)";
            req.Method = "POST";
            if (Proxy != null)
            {
                req.Proxy = Proxy;
            }
            req.Timeout     = HttpTimeout;
            req.ContentType = "multipart/form-data; boundary=" + boundary;
            //req.Expect = String.Empty;
            if (!String.IsNullOrEmpty(authHeader))
            {
                req.Headers["Authorization"] = authHeader;
            }

            req.ContentLength = dataBuffer.Length;

            using (Stream reqStream = req.GetRequestStream())
            {
                int bufferSize = 32 * 1024;
                if (dataBuffer.Length / 100 > bufferSize)
                {
                    bufferSize = bufferSize * 2;
                }

                int uploadedSoFar = 0;

                while (uploadedSoFar < dataBuffer.Length)
                {
                    reqStream.Write(dataBuffer, uploadedSoFar, Math.Min(bufferSize, dataBuffer.Length - uploadedSoFar));
                    uploadedSoFar += bufferSize;

                    if (OnUploadProgress != null)
                    {
                        UploadProgressEventArgs args = new UploadProgressEventArgs(uploadedSoFar, dataBuffer.Length);
                        OnUploadProgress(this, args);
                    }
                }
                reqStream.Close();
            }

            HttpWebResponse res = (HttpWebResponse)req.GetResponse();

            StreamReader sr = new StreamReader(res.GetResponseStream());
            string       s  = sr.ReadToEnd();

            sr.Close();
            return(s);
        }
All Usage Examples Of FlickrNet.FlickrResponder::OAuthCalculateAuthHeader