我想将文件发送到带有其他参数的Web服务 像这样:
C:\wamp64\www\symfony>php ../composer.phar update
Loading composer repositories with package information
Updating dependencies (including require-dev)
Package operations: 2 installs, 10 updates, 0 removals
我怎么能在C#中做到这一点 我试试这个:
param1=value1¶m2=value2¶m3=IMAGE_FILE
但那不起作用。
有解决方案吗?
更新:
此外,我尝试使用¶m3=Convert.ToBase64String(File.ReadAllBytes(txtlogo.Text))
这样的(我不知道它是正确的还是没有)
HttpContent
并且服务器不会收到HttpContent stringContent = new StringContent("param1=param1¶m2=param2");
FileStream file = new FileStream(txtlogo.Text, FileMode.Open);
HttpContent fileStreamContent = new StreamContent(file);
using (var client = new HttpClient())
using (var formData = new MultipartFormDataContent())
{
formData.Add(stringContent, "param1", "param1");
formData.Add(fileStreamContent, "file1", "file1");
var response = client.PostAsync("url", formData).Result;
if (!response.IsSuccessStatusCode)
{
string ss = "s";
}
string my = response.Content.ReadAsStringAsync().Result;
}
...
答案 0 :(得分:-1)
尝试使用get方法(简单)
try
{
using (var wc = new WebClient())
{
string url = "https://url.com/index.php?x=1222&y=filebase64-sdfsdfsdfsdfsdfsdfsdfsdfsd";
// Get account from accessToken
response = wc.DownloadString(url);
}
}
catch (Exception ee)
{
Console.WriteLine("Coś nie tak z pobieraniem kont");
}