本文整理汇总了C#中MultipartContent类的典型用法代码示例。如果您正苦于以下问题:C# MultipartContent类的具体用法?C# MultipartContent怎么用?C# MultipartContent使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
MultipartContent类属于命名空间,在下文中一共展示了MultipartContent类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的C#代码示例。
示例1: Get
public HttpResponseMessage Get(string file1, string file2)
{
var fileA = new StreamContent(new FileStream(Path.Combine(_root, file1), FileMode.Open));
fileA.Headers.ContentType = new MediaTypeHeaderValue("text/html");
var fileB = new StreamContent(new FileStream(Path.Combine(_root, file2), FileMode.Open));
fileA.Headers.ContentType = new MediaTypeHeaderValue("text/html");
var result = new HttpResponseMessage(HttpStatusCode.OK);
var content = new MultipartContent {fileA, fileB};
result.Content = content;
return result;
}
开发者ID:diouf,项目名称:apress-recipes-webapi,代码行数:14,代码来源:ItemsController.cs
示例2: PostNotification
public Task<HttpResponseMessage> PostNotification (BlackberryNotification notification)
{
var c = new MultipartContent ("related", Configuration.Boundary);
c.Headers.Remove("Content-Type");
c.Headers.TryAddWithoutValidation("Content-Type", "multipart/related; boundary=" + Configuration.Boundary + "; type=application/xml");
var xml = notification.ToPapXml ();
c.Add (new StringContent (xml, Encoding.UTF8, "application/xml"));
var bc = new ByteArrayContent(notification.Content.Content);
bc.Headers.Add("Content-Type", notification.Content.ContentType);
foreach (var header in notification.Content.Headers)
bc.Headers.Add(header.Key, header.Value);
c.Add(bc);
return PostAsync (Configuration.SendUrl, c);
}
开发者ID:Donnie888,项目名称:LxServer,代码行数:21,代码来源:BlackberryHttpClient.cs
示例3: PostData
public async Task<Result> PostData(Uri uri, MultipartContent header, StringContent content)
{
var httpClient = new HttpClient();
try
{
if (!string.IsNullOrEmpty(AuthenticationToken))
{
httpClient.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", AuthenticationToken);
}
HttpResponseMessage response;
if (header == null)
{
if(content == null) content = new StringContent(string.Empty);
response = await httpClient.PostAsync(uri, content);
}
else
{
response = await httpClient.PostAsync(uri, header);
}
var responseContent = await response.Content.ReadAsStringAsync();
return new Result(response.IsSuccessStatusCode, responseContent);
}
catch (Exception ex)
{
throw new WebException("Kinder Chat API Error: Service error", ex);
}
}
开发者ID:richardboegli,项目名称:KinderChat,代码行数:27,代码来源:WebManager.cs
示例4: ReadFromStreamAsyncShouldReturnUploadImageDataTest
public void ReadFromStreamAsyncShouldReturnUploadImageDataTest()
{
ImageMultipartMediaFormatter target = new ImageMultipartMediaFormatter();
Type type = typeof(UploadImageData);
Stream readStream = null;
MultipartContent content = new MultipartContent("form-data");
byte[] content_bytes=new byte[] { 10, 11, 12 };
StreamContent content_part = new StreamContent(new MemoryStream(content_bytes));
content_part.Headers.Add("Content-Disposition", @"form-data; name=fieldName; filename=image.jpg");
content_part.Headers.Add("Content-Type", "image/jpeg");
content.Add(content_part);
IFormatterLogger formatterLogger = null;
var actual = target.ReadFromStreamAsync(type, readStream, content, formatterLogger);
var actualResult = actual.Result;
Assert.IsInstanceOfType(actualResult,typeof(UploadImageData));
Assert.AreEqual(3, (actualResult as UploadImageData).ImageBuffer.Length);
for (int ind = 0; ind < 3; ind++)
{
Assert.AreEqual(content_bytes[ind], (actualResult as UploadImageData).ImageBuffer[ind]);
}
Assert.AreEqual("image.jpg", (actualResult as UploadImageData).FileName);
Assert.AreEqual("image/jpeg", (actualResult as UploadImageData).ImageType);
}
开发者ID:RomanAnosov,项目名称:Repo,代码行数:25,代码来源:ImageMultipartMediaFormatterTest.cs
示例5: RunTest
private static async Task RunTest(string baseAddress)
{
HttpClient client = new HttpClient();
HttpRequestMessage batchRequest = new HttpRequestMessage(
HttpMethod.Post,
baseAddress + "/api/batch"
);
MultipartContent batchContent = new MultipartContent("batch");
batchRequest.Content = batchContent;
CreateBatchedRequest(baseAddress, batchContent);
using (var stdout = Console.OpenStandardOutput())
{
Console.WriteLine("<<< REQUEST >>>");
Console.WriteLine();
Console.WriteLine(batchRequest);
Console.WriteLine();
await batchContent.CopyToAsync(stdout);
Console.WriteLine();
var batchResponse = await client.SendAsync(batchRequest);
Console.WriteLine("<<< RESPONSE >>>");
Console.WriteLine();
Console.WriteLine(batchResponse);
Console.WriteLine();
await batchResponse.Content.CopyToAsync(stdout);
Console.WriteLine();
Console.WriteLine();
}
}
开发者ID:srihari-sridharan,项目名称:Programming-Playground,代码行数:34,代码来源:Program.cs
示例6: ExecuteAsync
public async Task ExecuteAsync(string accessToken, string ebookId, int partCount, Func<Stream, Task> streamHandler)
{
var message = new HttpRequestMessage(HttpMethod.Post, new Uri("http://localhost:20394/api/batch"));
var content = new MultipartContent("mixed");
message.Content = content;
for (int i = 0; i < partCount; ++i)
{
content.Add(new HttpMessageContent(
new HttpRequestMessage(HttpMethod.Get, new Uri(string.Format("http://localhost:20394/api/ebooks/ebook/{0}/part/{1}", ebookId, i)))));
}
using (var client = new HttpClient())
{
client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", accessToken);
var response = await client.SendAsync(message);
var streamProvider = await response.Content.ReadAsMultipartAsync();
foreach (var partialContent in streamProvider.Contents)
{
var part = await partialContent.ReadAsHttpResponseMessageAsync();
var partStream = await part.Content.ReadAsStreamAsync();
await streamHandler(partStream);
}
}
}
开发者ID:jcorioland,项目名称:techdays-paris-2014-mvc-webapi,代码行数:26,代码来源:GetAllEbookPartsQuery.cs
示例7: Main
static void Main(string[] args)
{
var client = new HttpClient();
var batchRequest = new HttpRequestMessage(
HttpMethod.Post,
"http://fsatnav:8080/api/batch"
);
var batchContent = new MultipartContent("mixed");
batchRequest.Content = batchContent;
batchContent.Add(
new HttpMessageContent(
new HttpRequestMessage(
HttpMethod.Get,
"http://localhost:8080/api/products"
)
)
);
batchContent.Add(
new HttpMessageContent(
new HttpRequestMessage(
HttpMethod.Put,
"http://localhost:8080/api/products"
)
{
Content = new StringContent("{\"Name\":\"Product X\",\"StockQuantity\":300}", Encoding.UTF8, "application/json")
}
)
);
using (Stream stdout = Console.OpenStandardOutput())
{
Console.WriteLine("<<< REQUEST >>>");
Console.WriteLine();
Console.WriteLine(batchRequest);
Console.WriteLine();
batchContent.CopyToAsync(stdout).Wait();
Console.WriteLine();
var batchResponse = client.SendAsync(batchRequest).Result;
Console.WriteLine("<<< RESPONSE >>>");
Console.WriteLine();
Console.WriteLine(batchResponse);
Console.WriteLine();
batchResponse.Content.CopyToAsync(stdout).Wait();
Console.WriteLine();
Console.WriteLine();
}
Console.ReadLine();
}
开发者ID:jonsamwell,项目名称:angular-http-batcher,代码行数:54,代码来源:Program.cs
示例8: Add
public void Add()
{
var m = new MultipartContent ("a", "b");
var other = new MultipartContent ("2", "44");
other.Headers.Expires = new DateTimeOffset (2020, 11, 30, 19, 55, 22, TimeSpan.Zero);
m.Add (other);
Assert.AreEqual ("multipart/a", m.Headers.ContentType.MediaType, "#1");
Assert.AreEqual (114, m.Headers.ContentLength, "#2");
Assert.AreEqual ("--b\r\nContent-Type: multipart/2; boundary=\"44\"\r\nExpires: Mon, 30 Nov 2020 19:55:22 GMT\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");
}
开发者ID:RainsSoft,项目名称:dotnet-httpclient35,代码行数:13,代码来源:MultipartContentTest.cs
示例9: Main
static void Main(string[] args)
{
var client = new HttpClient();
var batchRequest = new HttpRequestMessage(
HttpMethod.Post,
"http://localhost:52857/api/$batch"
);
var batchContent = new MultipartContent("mixed");
batchRequest.Content = batchContent;
batchContent.Add(
new HttpMessageContent(
new HttpRequestMessage(
HttpMethod.Get,
"http://localhost:52857/api/TestClassOne"
)
)
);
batchContent.Add(
new HttpMessageContent(
new HttpRequestMessage(
HttpMethod.Get,
"http://localhost:52857/api/TestClassTwo"
)
)
);
using (Stream stdout = Console.OpenStandardOutput())
{
Console.WriteLine("<<< REQUEST >>>");
Console.WriteLine();
Console.WriteLine(batchRequest);
Console.WriteLine();
batchContent.CopyToAsync(stdout).Wait();
Console.WriteLine();
var batchResponse = client.SendAsync(batchRequest).Result;
Console.WriteLine("<<< RESPONSE >>>");
Console.WriteLine();
Console.WriteLine(batchResponse);
Console.WriteLine();
batchResponse.Content.CopyToAsync(stdout).Wait();
Console.WriteLine();
Console.WriteLine();
}
Console.ReadLine();
}
开发者ID:okusnadi,项目名称:AspNet5BatchingMiddleware,代码行数:51,代码来源:Program.cs
示例10: BeginBatch
public void BeginBatch()
{
_batchId = Guid.NewGuid().ToString();
_changesetId = Guid.NewGuid().ToString();
this.Request = CreateRequest(CreateRequestUrl(FluentCommand.BatchLiteral));
this.Request.Method = RestVerbs.POST;
var batchContent = new MultipartContent("mixed", "batch_" + _batchId);
this.Request.Content = batchContent;
this.Request.ContentType = "application/http";
var changesetContent = new MultipartContent("mixed", "changeset_" + _changesetId);
batchContent.Add(changesetContent);
_content = changesetContent;
}
开发者ID:rmagruder,项目名称:Simple.OData.Client,代码行数:14,代码来源:BatchRequestBuilder.cs
示例11: Add_2
public void Add_2()
{
var m = new MultipartContent ("a", "X");
var other = new MultipartContent ("2", "2a");
m.Add (other);
var other2 = new MultipartContent ("3", "3a");
other2.Headers.Add ("9", "9n");
m.Add (other2);
Assert.AreEqual ("multipart/a", m.Headers.ContentType.MediaType, "#1");
Assert.AreEqual (148, m.Headers.ContentLength, "#2");
Assert.AreEqual ("--X\r\nContent-Type: multipart/2; boundary=\"2a\"\r\n\r\n--2a\r\n\r\n--2a--\r\n\r\n--X\r\nContent-Type: multipart/3; boundary=\"3a\"\r\n9: 9n\r\n\r\n--3a\r\n\r\n--3a--\r\n\r\n--X--\r\n",
m.ReadAsStringAsync ().Result, "#3");
Assert.AreEqual (other, m.First (), "#4");
}
开发者ID:RainsSoft,项目名称:dotnet-httpclient35,代码行数:16,代码来源:MultipartContentTest.cs
示例12: PostConvertFile_ConvertToKml_ShouldReturnByteArray
public void PostConvertFile_ConvertToKml_ShouldReturnByteArray()
{
var multipartContent = new MultipartContent();
var streamContent = new StreamContent(new MemoryStream(new byte[1] { 1 }));
streamContent.Headers.ContentDisposition = new ContentDispositionHeaderValue("form-data")
{
Name = "\"files\"",
FileName = "\"SomeFile.twl\""
};
streamContent.Headers.ContentType = new MediaTypeHeaderValue("application/kml");
multipartContent.Add(streamContent);
_controller.Request = new HttpRequestMessage();
_controller.Request.Content = multipartContent;
_gpsBabelGateway.ConvertFileFromat(Arg.Any<byte[]>(), "naviguide", "kml").Returns(Task.FromResult(new byte[2] { 1, 1 }));
var response = _controller.PostConvertFile("kml").Result as OkNegotiatedContentResult<byte[]>;
Assert.AreEqual(2, response.Content.Length);
}
开发者ID:nonZero,项目名称:Site,代码行数:19,代码来源:ConvertFilesControllerTests.cs
示例13: Main
static void Main()
{
var address = "http://localhost:9000/";
using (WebApp.Start<Startup>(address))
{
var client = new HttpClient();
var batchContent = new MultipartContent("mixed")
{
new HttpMessageContent(new HttpRequestMessage(HttpMethod.Post, address + "/api/items")
{
Content = new ObjectContent(typeof (Item),
new Item {Country = "Switzerland", Id = 1, Name = "Filip"},
new JsonMediaTypeFormatter())
}),
new HttpMessageContent(new HttpRequestMessage(HttpMethod.Post, address + "/api/items")
{
Content =
new ObjectContent(typeof (Item), new Item {Country = "Canada", Id = 2, Name = "Felix"},
new JsonMediaTypeFormatter())
}),
new HttpMessageContent(new HttpRequestMessage(HttpMethod.Get, address + "/api/items"))
};
var batchRequest = new HttpRequestMessage(HttpMethod.Post, address + "/api/batch")
{
Content = batchContent
};
var batchResponse = client.SendAsync(batchRequest).Result;
var streamProvider = batchResponse.Content.ReadAsMultipartAsync().Result;
foreach (var content in streamProvider.Contents)
{
var response = content.ReadAsHttpResponseMessageAsync().Result;
Print(response);
}
Console.ReadLine();
}
}
开发者ID:diouf,项目名称:apress-recipes-webapi,代码行数:43,代码来源:Program.cs
示例14: Ctor
public void Ctor ()
{
using (var m = new MultipartContent ("a", "b")) {
m.Headers.Add ("extra", "value");
Assert.AreEqual ("multipart/a", m.Headers.ContentType.MediaType, "#1");
Assert.AreEqual (14, m.Headers.ContentLength, "#2");
Assert.AreEqual ("--b\r\n\r\n--b--\r\n", m.ReadAsStringAsync ().Result, "#3");
}
using (var m = new MultipartContent ()) {
Assert.AreEqual ("multipart/mixed", m.Headers.ContentType.MediaType, "#11");
Assert.AreEqual (84, m.Headers.ContentLength, "#12");
}
using (var m = new MultipartContent ("ggg")) {
Assert.AreEqual ("multipart/ggg", m.Headers.ContentType.MediaType, "#21");
Assert.AreEqual (84, m.Headers.ContentLength, "#22");
}
}
开发者ID:Profit0004,项目名称:mono,代码行数:19,代码来源:MultipartContentTest.cs
示例15: Build
public HttpContent Build(string boundary)
{
if (boundary == null)
{
throw new ArgumentNullException("boundary");
}
if (string.IsNullOrWhiteSpace(boundary))
{
throw new ArgumentException("The provided boundary value is invalid", "boundary");
}
MultipartContent content = new MultipartContent("mixed", boundary);
foreach (var request in Requests)
{
HttpMessageContent messageContent = new HttpMessageContent(request);
messageContent.Headers.ContentType = MediaTypeHeaderValue.Parse("application/http");
messageContent.Headers.Add("Content-Transfer-Encoding", "binary");
content.Add(messageContent);
}
return content;
}
开发者ID:ZhaoYngTest01,项目名称:WebApi,代码行数:20,代码来源:ODataChangeSet.cs
示例16: SetUpRequest
private HttpRequestMessage SetUpRequest(params string[] parts)
{
var content = new MultipartContent("mixed", "xyz-boundary");
foreach (var part in parts)
{
var nestedContent = new StringContent(part);
nestedContent.Headers.ContentType = new MediaTypeHeaderValue("application/http");
nestedContent.Headers.Add("Content-Transfer-Encoding", "binary");
content.Add(nestedContent);
}
var request = new HttpRequestMessage(HttpMethod.Post, "http://example.com/api/odata/$batch")
{
Content = content
};
request.Headers.Accept.Add(new MediaTypeWithQualityHeaderValue("application/xml+atom"));
return request;
}
开发者ID:battenworks,项目名称:NuGet.Lucene,代码行数:22,代码来源:HeaderCascadingODataBatchHandlerTests.cs
示例17: CreateResponseMessageAsync
public virtual Task<HttpResponseMessage> CreateResponseMessageAsync(IList<HttpResponseMessage> responses, HttpRequestMessage request, CancellationToken cancellationToken)
{
if (responses == null)
{
throw Error.ArgumentNull("responses");
}
if (request == null)
{
throw Error.ArgumentNull("request");
}
MultipartContent batchContent = new MultipartContent(MultiPartContentSubtype);
foreach (HttpResponseMessage batchResponse in responses)
{
batchContent.Add(new HttpMessageContent(batchResponse));
}
HttpResponseMessage response = request.CreateResponse();
response.Content = batchContent;
return Task.FromResult(response);
}
开发者ID:KevMoore,项目名称:aspnetwebstack,代码行数:22,代码来源:DefaultHttpBatchHandler.cs
示例18: SendAsync
protected override async Task<HttpResponseMessage> SendAsync(HttpRequestMessage request, CancellationToken cancellationToken)
{
if (request.Content == null ||
!request.Content.IsMimeMultipartContent("batch"))
{
return request.CreateErrorResponse(HttpStatusCode.UnsupportedMediaType, "The mediatype is expected to be \"multipart/batch\" for a batching request");
}
MultipartContent outerContent = new MultipartContent("batch");
HttpResponseMessage outerResponse = request.CreateResponse();
outerResponse.Content = outerContent;
MultipartMemoryStreamProvider multipart = await request.Content.ReadAsMultipartAsync();
/// Load requests from multipart content. Submit each of them
/// to the in memory batch server sequentially. They are then
/// processed asynchronously.
/// The individual response are gathered and added to the
/// multipart content for return response.
foreach (var content in multipart.Contents)
{
HttpResponseMessage innerResponse = null;
try
{
var innerRequest = await content.ReadAsHttpRequestMessageAsync();
innerResponse = await _entry.SendAsync(innerRequest, cancellationToken);
}
catch (Exception)
{
innerResponse = new HttpResponseMessage(HttpStatusCode.BadRequest);
}
outerContent.Add(new HttpMessageContent(innerResponse));
}
return outerResponse;
}
开发者ID:srihari-sridharan,项目名称:Programming-Playground,代码行数:39,代码来源:BatchHandler.cs
示例19: TestFileUpload
public async Task TestFileUpload()
{
var http = new HttpClient();
byte[] data = File.ReadAllBytes(HttpContext.Current.Server.MapPath("~/images/sailbig.jpg"));
var fileContent = new ByteArrayContent(data);
fileContent.Headers.ContentDisposition = new ContentDispositionHeaderValue("attachment")
{
FileName = "sailbig.jpg",
Name="file",
};
var mp = new MultipartContent();
mp.Add(fileContent);
var response = await http.PostAsync(BaseUrl + "samples/PostFileValues", mp);
Assert.IsTrue(response.IsSuccessStatusCode);
var result = await response.Content.ReadAsStringAsync();
Console.WriteLine(result);
}
开发者ID:vladkolesnik,项目名称:AspNetWebApiArticle,代码行数:24,代码来源:SimplePostVariableParameterBindingTests.cs
示例20: PostData
public async Task<Result> PostData(Uri uri, MultipartContent header, StringContent content, UserAccountEntity userAccountEntity)
{
var httpClient = new HttpClient();
try
{
var authenticationManager = new AuthenticationManager();
if (userAccountEntity.GetAccessToken().Equals("refresh"))
{
await authenticationManager.RefreshAccessToken(userAccountEntity);
}
var user = userAccountEntity.GetUserEntity();
if (user != null)
{
var language = userAccountEntity.GetUserEntity().Language;
httpClient.DefaultRequestHeaders.Add("Accept-Language", language);
}
httpClient.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", userAccountEntity.GetAccessToken());
HttpResponseMessage response;
if (header == null)
{
response = await httpClient.PostAsync(uri, content);
}
else
{
response = await httpClient.PostAsync(uri, header);
}
var responseContent = await response.Content.ReadAsStringAsync();
return new Result(true, responseContent);
}
catch
{
// TODO: Add detail error result to json object.
return new Result(false, string.Empty);
}
}
开发者ID:grit45,项目名称:PsnLib,代码行数:36,代码来源:WebManager.cs
注:本文中的MultipartContent类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论