Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- private confirmation SendDocument(string name, string pass, string fileName, byte[] content, string targetName)
- {
- _progressManager.SetCompleted("Отправка документа " + fileName);
- var request =
- (HttpWebRequest) WebRequest.Create("https://private.bus.gov.ru:443/gmu-integration-web/services/upload.");
- request.ContentType = string.Format("multipart/form-data; boundary={0}", Boundary);
- request.Method = "POST";
- request.KeepAlive = false;
- request.ProtocolVersion = HttpVersion.Version11;
- request.Proxy = ConfigurationManager.AppSettings
- .With(collection => collection.Get("E86n.Proxy"))
- .With(s => Regex.Match(s, @"http://(\w+):(\w+)@([a-zA-Z_0-9.]+):(\d{4})"))
- .With(
- match =>
- new WebProxy(match.Groups[3].Value, Convert.ToInt32(match.Groups[4].Value))
- {
- Credentials = new NetworkCredential(match.Groups[1].Value, match.Groups[2].Value),
- });
- // вроде как отменяем необходимость добавлять сертификат казначейства
- ServicePointManager.ServerCertificateValidationCallback += (sender, certificate, chain, errors) => true;
- string confirmationContent = string.Empty;
- string exceptionContent = string.Empty;
- ServicePointManager.SecurityProtocol = SecurityProtocolType.Ssl3 | SecurityProtocolType.Tls;
- try
- {
- using (var requestStream = new MemoryStream())
- {
- using (var streamWriter = new StreamWriter(requestStream))
- {
- streamWriter.WriteLine("--{0}", Boundary);
- streamWriter.WriteLine("Content-Disposition: form-data; name=\"login\"");
- streamWriter.WriteLine();
- streamWriter.WriteLine(name);
- streamWriter.WriteLine("--{0}", Boundary);
- streamWriter.WriteLine("Content-Disposition: form-data; name=\"password\"");
- streamWriter.WriteLine();
- streamWriter.WriteLine(pass);
- streamWriter.WriteLine("--{0}", Boundary);
- streamWriter.WriteLine(
- "Content-Disposition: form-data; name=\"document\";filename=\"{0}_{1}_{2}\"",
- fileName,
- DateTime.Now.ToString("yyyymmddhhmmss"),
- "001");
- streamWriter.WriteLine("Content-Type: text/xml");
- streamWriter.WriteLine();
- var r = Encoding.UTF8.GetChars(content);
- string rs = new string(r);
- streamWriter.WriteLine(Encoding.UTF8.GetChars(content));
- streamWriter.WriteLine("--{0}--", Boundary);
- streamWriter.Flush();
- request.ContentLength = streamWriter.BaseStream.Length;
- }
- string result = Encoding.ASCII.GetString(requestStream.ToArray());
- using (var streamWriter = new BinaryWriter(request.GetRequestStream()))
- {
- streamWriter.Write(requestStream.ToArray());
- }
- }
- using (
- StreamReader responseReader = request.GetResponse()
- .GetResponseStream()
- .With(stream => new StreamReader(stream)))
- {
- confirmationContent = responseReader.ReadToEnd();
- }
- }
- catch (Exception e)
- {
- exceptionContent = e.ExpandException();
- throw;
- }
- finally
- {
- SaveSendState(fileName, content, confirmationContent, targetName, exceptionContent);
- }
- var p = request.ToString();
- return confirmation.Parse(confirmationContent);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement