/** * Multipart example */ private static async Task FormpostmultipartAsync( Bootstrap bootstrap, Uri uriFile, IHttpDataFactory factory, IList <HeaderEntry <AsciiString, ICharSequence> > headers, List <IInterfaceHttpData> bodylist) { // XXX /formpostmultipart // Start the connection attempt. IChannel channel = await bootstrap.ConnectAsync(new IPEndPoint(ClientSettings.Host, ClientSettings.Port)); // Prepare the HTTP request. var request = new DefaultHttpRequest(DotNetty.Codecs.Http.HttpVersion.Http11, HttpMethod.Post, uriFile.ToString()); // Use the PostBody encoder HttpPostRequestEncoder bodyRequestEncoder = new HttpPostRequestEncoder(factory, request, true); // true => multipart // it is legal to add directly header or cookie into the request until finalize foreach (var entry in headers) { request.Headers.Set(entry.Key, entry.Value); } // add Form attribute from previous request in formpost() bodyRequestEncoder.SetBodyHttpDatas(bodylist); // finalize request bodyRequestEncoder.FinalizeRequest(); var list = new List <object>(); // send request list.Add(request); // test if request was chunked and if so, finish the write if (bodyRequestEncoder.IsChunked) { list.Add(bodyRequestEncoder); } await channel.WriteAndFlushManyAsync(list); // Now no more use of file representation (and list of HttpData) bodyRequestEncoder.CleanFiles(); // Wait for the server to close the connection. await channel.CloseCompletion; }