我要发送邮件到/ document(swagger),后者应使用
的正文内容上传文档f1 <- function(dat, rank = 1) {
purrr::imap(dat, ~
dat %>%
count(!! rlang::sym(.y)) %>%
rename_all(~ c('variable', 'counts')) %>%
arrange(desc(counts)) %>%
slice(seq_len(rank))) #%>%
#bind_cols - convert to a data.frame
}
f1(mtcars, 2)
后台使用的是swagger / document,所以我相信我的标题没有正确显示。
问题是我没有得到需要发送的标头的正确组合:
{
"Application": "tickets",
"File": "some binary data"
}
响应:
Authorization : xxxx;
Content-Type : multipart/form-data;
Content-Type : image/png;
Content-Type : application/json;
FileName : file_name
答案 0 :(得分:0)
FileInfo fi = new FileInfo(@"file");
byte[] fileContents = File.ReadAllBytes(fi.FullName);
ByteArrayContent byteArrayContent = new ByteArrayContent(fileContents);
byteArrayContent.Headers.ContentType = new MediaTypeHeaderValue("application/octet-stream");
byteArrayContent.Headers.ContentDisposition = new ContentDispositionHeaderValue("form-data")
{
FileName = fi.Name,
};
MultipartFormDataContent multiPartContent = new MultipartFormDataContent();
multiPartContent.Add(new StringContent("document storage"), "Application");
multiPartContent.Add(byteArrayContent, "File");
string header = string.Format("WRAP access_token=\"{0}\"", "xxxx");
HttpRequestMessage request = new HttpRequestMessage(HttpMethod.Post, "/document");
request.Headers.Add("Authorization", header);
request.Content = multiPartContent;
HttpClient httpClient = new HttpClient();
try
{
Task<HttpResponseMessage> httpRequest = httpClient.SendAsync(request, HttpCompletionOption.ResponseContentRead, CancellationToken.None);
HttpResponseMessage httpResponse = httpRequest.Result;
HttpStatusCode statusCode = httpResponse.StatusCode;
HttpContent responseContent = httpResponse.Content;
if (responseContent != null)
{
Task<String> stringContentsTask = responseContent.ReadAsStringAsync();
String stringContents = stringContentsTask.Result;
}
}
catch (Exception ex)
{
Console.WriteLine(ex.Message);
}