我试图使用后多System.Net.Http.HttpClient数据,所得到的响应是200 OK。
下面是我用的方法:
public async Task postMultipart()
{
var client = new HttpClient();
client.DefaultRequestHeaders.TryAddWithoutValidation("Content-Type", "multipart/form-data");
// This is the postdata
MultipartFormDataContent content = new MultipartFormDataContent( );
content.Add(new StringContent("12", Encoding.UTF8), "userId");
content.Add(new StringContent("78", Encoding.UTF8), "noOfAttendees");
content.Add(new StringContent("chennai", Encoding.UTF8), "locationName");
content.Add(new StringContent("32.56", Encoding.UTF8), "longitude");
content.Add(new StringContent("32.56", Encoding.UTF8), "latitude");
Console.Write(content);
// upload the file sending the form info and ensure a result.
// it will throw an exception if the service doesn't return a valid successful status code
await client.PostAsync(fileUploadUrl, content)
.ContinueWith((postTask) =>
{
postTask.Result.EnsureSuccessStatusCode();
});
}
- 如何从这种方法获得的响应主体?