0
我試圖上傳coverity掃描結果以覆蓋。Https上傳MultipartForm返回401未授權
這是我的代碼:
public static void Main(String[] args)
{
var client = new HttpClient
{
Timeout = TimeSpan.FromMinutes(20)
};
var form = new MultipartFormDataContent
{
{ new StringContent("my tooken"), "token" },
{ new StringContent("my email"), "email" },
{ new StringContent("1.1.1.1"), "version" },
{ new StringContent("Test..."), "description" }
};
var fs = new FileStream(@"cov-int.zip", FileMode.Open, FileAccess.Read);
form.Add(new StreamContent(fs), "file", "cov-int.zip");
var task = client.PostAsync("https://scan.coverity.com/builds?project=Name/Porject", form);
try
{
task.Wait();
}
catch (AggregateException ex)
{
throw ex.InnerException;
}
var result = task.Result;
fs.Close();
}
的職位總是以失敗狀態(401未經授權)結束:
{StatusCode: 401, ReasonPhrase: 'Unauthorized', Version: 1.1, Content: System.Net.Http.StreamContent, Headers:
{
x-xss-protection: 1; mode=block
x-request-id: 70dfc119-7d78-47fe-86a7-8505d73225e4
x-runtime: 1.675468
x-frame-options: SAMEORIGIN
x-content-type-options: nosniff
Connection: close
Status: 401 Unauthorized
Transfer-Encoding: chunked
Cache-Control: no-cache
Date: Fri, 29 May 2015 13:01:06 GMT
Server: Apache
X-Powered-By: Phusion Passenger 5.0.8
Content-Type: text/html; charset=utf-8
}}
我試着上傳相同的數據,從同一臺機器到使用捲曲的相同服務器:
curl --form token="token" --form email="email" --form file="cov-int.zip" --form version="1.1.1.1" --form description="a message" --insecure https://scan.coverity.com/builds?project=Name/Project
使用捲曲工作上傳數據。
我在C#代碼中做錯了什麼?
在我看來,你的C#代碼沒有以正確的格式發佈HTTP請求。看看如何確保它是一個多部分Post HTTP請求。 – AndreCruz
我無法找到任何錯誤的格式化數據。請求看起來不錯。 – musium