示例#1
0
 public override void CopyFrom(HTTPFormBase fields)
 {
     //IL_001f: Unknown result type (might be due to invalid IL or missing references)
     //IL_0029: Expected O, but got Unknown
     base.Fields    = fields.Fields;
     base.IsChanged = true;
     if (Form == null)
     {
         Form = new WWWForm();
         if (base.Fields != null)
         {
             for (int i = 0; i < base.Fields.Count; i++)
             {
                 HTTPFieldData hTTPFieldData = base.Fields[i];
                 if (string.IsNullOrEmpty(hTTPFieldData.Text) && hTTPFieldData.Binary != null)
                 {
                     Form.AddBinaryData(hTTPFieldData.Name, hTTPFieldData.Binary, hTTPFieldData.FileName, hTTPFieldData.MimeType);
                 }
                 else
                 {
                     Form.AddField(hTTPFieldData.Name, hTTPFieldData.Text, hTTPFieldData.Encoding);
                 }
             }
         }
     }
 }
示例#2
0
        public override byte[] GetData()
        {
            if (CachedData != null)
            {
                return(CachedData);
            }
            using (MemoryStream memoryStream = new MemoryStream())
            {
                for (int i = 0; i < base.Fields.Count; i++)
                {
                    HTTPFieldData hTTPFieldData = base.Fields[i];
                    memoryStream.WriteLine("--" + Boundary);
                    memoryStream.WriteLine("Content-Disposition: form-data; name=\"" + hTTPFieldData.Name + "\"" + (string.IsNullOrEmpty(hTTPFieldData.FileName) ? string.Empty : ("; filename=\"" + hTTPFieldData.FileName + "\"")));
                    if (!string.IsNullOrEmpty(hTTPFieldData.MimeType))
                    {
                        memoryStream.WriteLine("Content-Type: " + hTTPFieldData.MimeType);
                    }
                    memoryStream.WriteLine("Content-Length: " + hTTPFieldData.Payload.Length.ToString());
                    memoryStream.WriteLine();
                    memoryStream.Write(hTTPFieldData.Payload, 0, hTTPFieldData.Payload.Length);
                    memoryStream.Write(HTTPRequest.EOL, 0, HTTPRequest.EOL.Length);
                }
                memoryStream.WriteLine("--" + Boundary + "--");
                base.IsChanged = false;
                return(CachedData = memoryStream.ToArray());

IL_014f:
                byte[] result;
                return(result);
            }
        }
示例#3
0
        public void AddBinaryData(string fieldName, byte[] content, string fileName, string mimeType)
        {
            if (Fields == null)
            {
                Fields = new List <HTTPFieldData>();
            }
            HTTPFieldData hTTPFieldData = new HTTPFieldData();

            hTTPFieldData.Name = fieldName;
            if (fileName == null)
            {
                hTTPFieldData.FileName = fieldName + ".dat";
            }
            else
            {
                hTTPFieldData.FileName = fileName;
            }
            if (mimeType == null)
            {
                hTTPFieldData.MimeType = "application/octet-stream";
            }
            else
            {
                hTTPFieldData.MimeType = mimeType;
            }
            hTTPFieldData.Binary = content;
            Fields.Add(hTTPFieldData);
            bool hasBinary = IsChanged = true;

            HasBinary = hasBinary;
        }
示例#4
0
        public void AddField(string fieldName, string value, Encoding e)
        {
            if (Fields == null)
            {
                Fields = new List <HTTPFieldData>();
            }
            HTTPFieldData hTTPFieldData = new HTTPFieldData();

            hTTPFieldData.Name     = fieldName;
            hTTPFieldData.FileName = null;
            hTTPFieldData.MimeType = "text/plain; charset=\"" + e.WebName + "\"";
            hTTPFieldData.Text     = value;
            hTTPFieldData.Encoding = e;
            Fields.Add(hTTPFieldData);
            IsChanged     = true;
            HasLongValue |= (value.Length > 256);
        }
示例#5
0
        public override byte[] GetData()
        {
            if (CachedData != null && !base.IsChanged)
            {
                return(CachedData);
            }
            StringBuilder stringBuilder = new StringBuilder();

            for (int i = 0; i < base.Fields.Count; i++)
            {
                HTTPFieldData hTTPFieldData = base.Fields[i];
                if (i > 0)
                {
                    stringBuilder.Append("&");
                }
                stringBuilder.Append(EscapeDataStringHelper(hTTPFieldData.Name));
                stringBuilder.Append("=");
                try
                {
                    if (!string.IsNullOrEmpty(hTTPFieldData.Text) || hTTPFieldData.Binary == null)
                    {
                        stringBuilder.Append(EscapeDataStringHelper(hTTPFieldData.Text));
                    }
                    else
                    {
                        stringBuilder.Append(EscapeDataStringHelper(Encoding.UTF8.GetString(hTTPFieldData.Binary, 0, hTTPFieldData.Binary.Length)));
                    }
                }
                catch (FormatException ex)
                {
                    Debug.LogErrorFormat("Could not escape field {0} using data {1}", new object[2]
                    {
                        hTTPFieldData.Name,
                        hTTPFieldData.Text
                    });
                    Debug.LogException((Exception)ex);
                }
            }
            base.IsChanged = false;
            return(CachedData = Encoding.UTF8.GetBytes(stringBuilder.ToString()));
        }