public override byte[] GetData() { if ((this.CachedData != null) && !base.IsChanged) { return(this.CachedData); } StringBuilder builder = new StringBuilder(); for (int i = 0; i < base.Fields.Count; i++) { HTTPFieldData data = base.Fields[i]; if (i > 0) { builder.Append("&"); } builder.Append(EscapeString(data.Name)); builder.Append("="); if (!string.IsNullOrEmpty(data.Text) || (data.Binary == null)) { builder.Append(EscapeString(data.Text)); } else { builder.Append(EscapeString(Encoding.UTF8.GetString(data.Binary, 0, data.Binary.Length))); } } base.IsChanged = false; return(this.CachedData = Encoding.UTF8.GetBytes(builder.ToString())); }
public void AddBinaryData(string fieldName, byte[] content, string fileName, string mimeType) { if (Fields == null) { Fields = new List <HTTPFieldData>(); } HTTPFieldData field = new HTTPFieldData(); field.Name = fieldName; if (fileName == null) { field.FileName = fieldName + ".dat"; } else { field.FileName = fileName; } if (mimeType == null) { field.MimeType = "application/octet-stream"; } else { field.MimeType = mimeType; } field.Binary = content; Fields.Add(field); HasBinary = IsChanged = true; }
public override byte[] GetData() { if (this.CachedData != null) { return(this.CachedData); } using (MemoryStream stream = new MemoryStream()) { for (int i = 0; i < base.Fields.Count; i++) { HTTPFieldData data = base.Fields[i]; stream.WriteLine("--" + this.Boundary); stream.WriteLine("Content-Disposition: form-data; name=\"" + data.Name + "\"" + (string.IsNullOrEmpty(data.FileName) ? string.Empty : ("; filename=\"" + data.FileName + "\""))); if (!string.IsNullOrEmpty(data.MimeType)) { stream.WriteLine("Content-Type: " + data.MimeType); } stream.WriteLine("Content-Length: " + data.Payload.Length.ToString()); stream.WriteLine(); stream.Write(data.Payload, 0, data.Payload.Length); stream.Write(HTTPRequest.EOL, 0, HTTPRequest.EOL.Length); } stream.WriteLine("--" + this.Boundary + "--"); base.IsChanged = false; return(this.CachedData = stream.ToArray()); } }
public void AddBinaryData(string fieldName, byte[] content, string fileName, string mimeType) { if (this.Fields == null) { this.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; this.Fields.Add(hTTPFieldData); bool flag = true; this.IsChanged = flag; this.HasBinary = flag; }
public void AddField(string fieldName, string value, Encoding e) { if (this.Fields == null) { this.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; this.Fields.Add(hTTPFieldData); this.IsChanged = true; this.HasLongValue |= (value.Length > 256); }
public override byte[] GetData() { if (CachedData != null) { return(CachedData); } using (System.IO.MemoryStream ms = new System.IO.MemoryStream()) { for (int i = 0; i < Fields.Count; ++i) { HTTPFieldData field = Fields[i]; // Set the boundary ms.WriteLine("--" + Boundary); // Set up Content-Disposition header to our form with the name ms.WriteLine("Content-Disposition: form-data; name=\"" + field.Name + "\"" + (!string.IsNullOrEmpty(field.FileName) ? "; filename=\"" + field.FileName + "\"" : string.Empty)); // Set up Content-Type head for the form. if (!string.IsNullOrEmpty(field.MimeType)) { ms.WriteLine("Content-Type: " + field.MimeType); } ms.WriteLine("Content-Length: " + field.Payload.Length.ToString()); ms.WriteLine(); // Write the actual data to the MemoryStream ms.Write(field.Payload, 0, field.Payload.Length); ms.Write(HTTPRequest.EOL, 0, HTTPRequest.EOL.Length); } // Write out the trailing boundary ms.WriteLine("--" + Boundary + "--"); IsChanged = false; // Set the RawData of our request return(CachedData = ms.ToArray()); } }
public void AddField(string fieldName, string value, System.Text.Encoding e) { if (Fields == null) { Fields = new List <HTTPFieldData>(); } HTTPFieldData field = new HTTPFieldData(); field.Name = fieldName; field.FileName = null; field.MimeType = "text/plain; charset=\"" + e.WebName + "\""; field.Text = value; field.Encoding = e; Fields.Add(field); IsChanged = true; HasLongValue |= value.Length > LongLength; }
public override void CopyFrom(HTTPFormBase fields) { base.Fields = fields.Fields; base.IsChanged = true; if (this.Form == null) { this.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) { this.Form.AddBinaryData(hTTPFieldData.Name, hTTPFieldData.Binary, hTTPFieldData.FileName, hTTPFieldData.MimeType); } else { this.Form.AddField(hTTPFieldData.Name, hTTPFieldData.Text, hTTPFieldData.Encoding); } } } } }
public void AddBinaryData(string fieldName, byte[] content, string fileName, string mimeType) { if (Fields == null) Fields = new List<HTTPFieldData>(); HTTPFieldData field = new HTTPFieldData(); field.Name = fieldName; if (fileName == null) field.FileName = fieldName + ".dat"; else field.FileName = fileName; if (mimeType == null) field.MimeType = "application/octet-stream"; else field.MimeType = mimeType; field.Binary = content; Fields.Add(field); HasBinary = IsChanged = true; }
public void AddField(string fieldName, string value, System.Text.Encoding e) { if (Fields == null) Fields = new List<HTTPFieldData>(); HTTPFieldData field = new HTTPFieldData(); field.Name = fieldName; field.FileName = null; field.MimeType = "text/plain; charset=\"" + e.WebName + "\""; field.Text = value; field.Encoding = e; Fields.Add(field); IsChanged = true; HasLongValue |= value.Length > LongLength; }