Tak jsem to nakonec rozlouskl. WebClient.UploadFile() neumožňuje spolu se soubory poslat i pole s hodnotami. Musel jsem nakonec odchytit úspěšný $curl post ve fiddlerovi a pak ho vytvořit 1:1 v C#. Tady je výsledek, sice dost neuhlazený, ale to už si každý zvládne případně upravit sám:
string boundary = DateTime.Now.Ticks.ToString("x", System.Globalization.NumberFormatInfo.InvariantInfo);
var request = WebRequest.Create(url);
request.Method = "POST";
request.ContentType = "multipart/form-data; boundary=----------------------------" + boundary;
var requestStream = request.GetRequestStream();
var buffer = Encoding.ASCII.GetBytes("------------------------------" + boundary);
requestStream.Write(buffer, 0, buffer.Length);
buffer = Encoding.ASCII.GetBytes(string.Format("{0}Content-Disposition: form-data; name=\"file\"; filename=\"_temp.ipa\"{0}", Environment.NewLine));
requestStream.Write(buffer, 0, buffer.Length);
buffer = Encoding.ASCII.GetBytes(string.Format("Content-Type: application/octet-stream{0}{0}", Environment.NewLine));
requestStream.Write(buffer, 0, buffer.Length);
buffer = File.ReadAllBytes(filePath);
requestStream.Write(buffer, 0, buffer.Length);
buffer = Encoding.ASCII.GetBytes("------------------------------" + boundary);
requestStream.Write(buffer, 0, buffer.Length);
buffer = Encoding.ASCII.GetBytes(string.Format("{0}Content-Disposition: form-data; name=\"api_token\"{0}{0}", Environment.NewLine));
requestStream.Write(buffer, 0, buffer.Length);
buffer = Encoding.ASCII.GetBytes(string.Format("#####{0}", Environment.NewLine));
requestStream.Write(buffer, 0, buffer.Length);
buffer = Encoding.ASCII.GetBytes("------------------------------" + boundary);
requestStream.Write(buffer, 0, buffer.Length);
buffer = Encoding.ASCII.GetBytes(string.Format("{0}Content-Disposition: form-data; name=\"team_token\"{0}{0}", Environment.NewLine));
requestStream.Write(buffer, 0, buffer.Length);
buffer = Encoding.ASCII.GetBytes(string.Format("#####{0}", Environment.NewLine));
requestStream.Write(buffer, 0, buffer.Length);
buffer = Encoding.ASCII.GetBytes("------------------------------" + boundary);
requestStream.Write(buffer, 0, buffer.Length);
buffer = Encoding.ASCII.GetBytes(string.Format("{0}Content-Disposition: form-data; name=\"notes\"{0}{0}", Environment.NewLine));
requestStream.Write(buffer, 0, buffer.Length);
buffer = Encoding.ASCII.GetBytes(string.Format("test{0}", Environment.NewLine));
requestStream.Write(buffer, 0, buffer.Length);
buffer = Encoding.ASCII.GetBytes("------------------------------" + boundary + "--");
requestStream.Write(buffer, 0, buffer.Length);
requestStream.Close();
WebResponse response = request.GetResponse();
StreamReader responseReader = new StreamReader(response.GetResponseStream());
string result = responseReader.ReadToEnd();
responseReader.Close();
response.Close();
return result;
|