我在
给出的Curl中有这个多部分形式的POST请求 curl -u user:pass -H "Expect: " -F "file=@"C:\Users\Desktop\45.gpx -F description=test -F tags=xxxx -F visibility=xxxx http://www.openstreetmap/api/0.6/gpx/create
我一直在尝试将其转换为C#,但不知怎的,我一直收到错误的请求错误400。
System.Collections.Specialized.NameValueCollection reqparm = new System.Collections.Specialized.NameValueCollection();
reqparm.Add("description", "test");
reqparm.Add("tags", "upload");
reqparm.Add("visibility", "public");
reqparm.Add("file", fileName);
using (WebClient client = new WebClient())
{
try
{
client.Credentials = new NetworkCredential("user", "pass");
//client.Headers.Add("description", "test");
//client.Headers.Add("tags", "upload");
//client.Headers.Add("visibility", "public");
//client.Headers.Add("file", fileName);
byte[] responsebytes = client.UploadValues(url, "POST",reqparm);
string responsebody = Encoding.UTF8.GetString(responsebytes);
Console.WriteLine(responsebody);
}
catch (WebException ex)
{
Console.WriteLine(ex.Message);
}
}
答案 0 :(得分:0)