Exemple #1
0
        static void WriteMulitPart_Item(string key, MulitPartItem value, System.IO.Stream stream)
        {
            /*
             * -----------------------------7dc19db140126
             * Content-Disposition: form-data; name="litpic"; filename=""
             * Content-Type: application/octet-stream
             *
             *
             * -----------------------------7dc19db140126*/

            stream.Write(_mulitPartFormKeyBefore, 0, _mulitPartFormKeyBefore.Length);
            byte[] buffer = System.Text.Encoding.ASCII.GetBytes(key);
            stream.Write(buffer, 0, buffer.Length);
            if (value.Attributes != null && value.Attributes.Count > 0)
            {
                foreach (KeyValuePair <string, object> pair in value.Attributes)
                {
                    buffer = System.Text.Encoding.ASCII.GetBytes("\"; " + pair.Key + "=\"" + (pair.Value == null ? string.Empty : pair.Value.ToString()));
                    stream.Write(buffer, 0, buffer.Length);
                }
            }
            if (value.Headers != null && value.Headers.Count > 0)
            {
                buffer = System.Text.Encoding.ASCII.GetBytes("\"\r\n");
                stream.Write(buffer, 0, buffer.Length);
                string line = null;
                foreach (KeyValuePair <string, object> pair in value.Headers)
                {
                    line   = pair.Key + ": " + pair.Value + "\r\n";
                    buffer = System.Text.Encoding.ASCII.GetBytes(line);
                    stream.Write(buffer, 0, buffer.Length);
                }
                line   = "\r\n";
                buffer = System.Text.Encoding.ASCII.GetBytes(line);
                stream.Write(buffer, 0, buffer.Length);
            }
            else
            {
                stream.Write(_mulitPartFormKeyAfter, 0, _mulitPartFormKeyAfter.Length);
            }
            if (value.Value != null)
            {
                stream.Write(value.Value, 0, value.Value.Length);
            }
            WriteMulitPart_Spliter(stream);
        }
Exemple #2
0
        static void WriteMulitPart_Any(string key, object value, System.IO.Stream stream, System.Text.Encoding encoding)
        {
            if (value is string || value == null)
            {
                WriteMulitPart_String(key, (string)value, stream, encoding);
                return;
            }
            MulitPartItem item = value as MulitPartItem;

            if (item != null)
            {
                WriteMulitPart_Item(key, item, stream);
                return;
            }

            byte[] valueByteArray = value as byte[];
            if (valueByteArray != null)
            {
                WriteMulitPart_ByteArray(key, valueByteArray, stream);
                return;
            }
            IEnumerable <byte> valueByteE = value as IEnumerable <byte>;

            if (valueByteE != null)
            {
                WriteMulitPart_Bytes(key, valueByteE, stream);
                return;
            }
            System.Collections.IEnumerable e = value as System.Collections.IEnumerable;
            if (e != null)
            {
                WriteMulitPart_Mulit(key, e, stream, encoding);
                return;
            }
            WriteMulitPart_String(key, value == null ? string.Empty : value.ToString(), stream, encoding);
        }