本文整理汇总了C#中System.Net.Http.MultipartFormDataContent.ReadAsStringAsync方法的典型用法代码示例。如果您正苦于以下问题:C# MultipartFormDataContent.ReadAsStringAsync方法的具体用法?C# MultipartFormDataContent.ReadAsStringAsync怎么用?C# MultipartFormDataContent.ReadAsStringAsync使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类System.Net.Http.MultipartFormDataContent
的用法示例。
在下文中一共展示了MultipartFormDataContent.ReadAsStringAsync方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Add_2
public void Add_2()
{
var m = new MultipartFormDataContent ("b");
var other = new MultipartFormDataContent ("44");
m.Add (other, "name", "fname");
Assert.AreEqual ("multipart/form-data", m.Headers.ContentType.MediaType, "#1");
Assert.AreEqual (165, m.Headers.ContentLength, "#2");
Assert.AreEqual ("--b\r\nContent-Type: multipart/form-data; boundary=\"44\"\r\nContent-Disposition: form-data; name=name; filename=fname; filename*=utf-8''fname\r\n\r\n--44\r\n\r\n--44--\r\n\r\n--b--\r\n", m.ReadAsStringAsync ().Result, "#3");
Assert.AreEqual (other, m.First (), "#4");
Assert.IsNull (m.Headers.ContentDisposition, "#5");
Assert.AreEqual ("form-data; name=name; filename=fname; filename*=utf-8''fname", other.Headers.ContentDisposition.ToString (), "#6");
}
示例2: Add
public void Add()
{
var m = new MultipartFormDataContent ("b");
var other = new MultipartFormDataContent ("44");
other.Headers.Expires = new DateTimeOffset (2020, 11, 30, 19, 55, 22, TimeSpan.Zero);
m.Add (other);
Assert.AreEqual ("multipart/form-data", m.Headers.ContentType.MediaType, "#1");
Assert.AreEqual (154, m.Headers.ContentLength, "#2");
Assert.AreEqual ("--b\r\nContent-Type: multipart/form-data; boundary=\"44\"\r\nExpires: Mon, 30 Nov 2020 19:55:22 GMT\r\nContent-Disposition: form-data\r\n\r\n--44\r\n\r\n--44--\r\n\r\n--b--\r\n", m.ReadAsStringAsync ().Result, "#3");
Assert.AreEqual (other, m.First (), "#4");
Assert.IsNull (m.Headers.ContentDisposition, "#5");
Assert.AreEqual ("form-data", other.Headers.ContentDisposition.ToString (), "#6");
}
示例3: Ctor
public void Ctor ()
{
using (var m = new MultipartFormDataContent ("b")) {
m.Headers.Add ("extra", "value");
Assert.AreEqual ("multipart/form-data", m.Headers.ContentType.MediaType, "#1");
Assert.IsNull (m.Headers.ContentDisposition, "#2");
Assert.AreEqual (14, m.Headers.ContentLength, "#3");
Assert.AreEqual ("--b\r\n\r\n--b--\r\n", m.ReadAsStringAsync ().Result, "#4");
}
using (var m = new MultipartFormDataContent ()) {
Assert.AreEqual ("multipart/form-data", m.Headers.ContentType.MediaType, "#11");
Assert.AreEqual (84, m.Headers.ContentLength, "#12");
}
using (var m = new MultipartFormDataContent ("ggg")) {
Assert.AreEqual ("multipart/form-data", m.Headers.ContentType.MediaType, "#21");
Assert.AreEqual (18, m.Headers.ContentLength, "#22");
}
}
示例4: UploadToServer
/**
* Converts the Report to the Web Server's desired format, JSON.
* It then posts the JSON file to the upload address above.
**/
public async Task<Boolean> UploadToServer() {
HttpClient client = new HttpClient();
client.BaseAddress = uploadAddress;
// In here, a MIME container is used to initialize the JSON form.
MultipartFormDataContent form = new MultipartFormDataContent();
//create the string for description, tags, and geolocation
HttpContent content = new StringContent(ConvertReportInformationForUpload());
form.Add(content, "\"data\"");
//convert image into byte array so we can create a memorystream
HttpContent image = new StreamContent(new MemoryStream(await convertImageToByte()));
image.Headers.ContentDisposition = new ContentDispositionHeaderValue("form-data") {
Name = "\"image\"",
FileName = "\"" + pollutionImage.Name + "\""
};
image.Headers.ContentType = new MediaTypeHeaderValue("image/jpeg");
form.Add(image);
Debug.WriteLine(client.DefaultRequestHeaders.ToString());
Debug.WriteLine(form.Headers);
Debug.WriteLine((await form.ReadAsStringAsync()) + "\n");
//try and post to server
var response = await client.PostAsync(uploadAddress, form);
Debug.WriteLine(response);
return response.IsSuccessStatusCode;
}