1
我有一個SSIS中的C#腳本,通過它的API將數據發送給第三方(這是迄今爲止我所遇到過的最糟糕的API!)。如何在POST請求中的HTTP字段添加另一個值?
無論如何,它對於如何接收數據非常敏感。該API接收CSV內容,具有以下工作:
Content-Type: text/plain; charset=utf-8
Content-Disposition: form-data; name="values"; filename="name.txt"
"test1073R","2016-02-23T00:00","0.00","0.00"
但是這一次沒有:
Content-Type: text/plain; charset=utf-8
Content-Disposition: form-data; name="values"
"test1073R","2016-02-23T00:00","0.00","0.00"
的區別在於filename="name.txt"
具有發送。
該數據直接從變量發送 - 它不會先寫入字符串。以下是我創建HTTP請求的代碼,但我不確定如何將filename="name.txt"
添加到請求中。有任何想法嗎?
using (var client = new HttpClient())
{
using (var multipartFormDataContent = new MultipartFormDataContent())
{
var values = new[]
{
new KeyValuePair<string, string>("customerid", Variables.BeonicCustomerId),
new KeyValuePair<string, string>("username", Variables.BeonicUsername),
new KeyValuePair<string, string>("password", Variables.BeonicPassword),
new KeyValuePair<string, string>("values", dataSb.ToString())
};
foreach (var keyValuePair in values)
{
multipartFormDataContent.Add(new StringContent(keyValuePair.Value),
String.Format("\"{0}\"", keyValuePair.Key));
}
Ta。訣竅了 – Lock