我想将数据发布到 REST API,但它没有创建正确的请求:using (var client = new HttpClient()){client.DefaultRequestHeaders.Add("Accept", "text/csv");HttpResponseMessage response = null;string baseUrl = ServiceUrl + "/api/v25/upload/test";Dictionary<string, string> parameters = new Dictionary<string, string>();parameters.Add("field1", "value1");parameters.Add("field2", "value2");MultipartFormDataContent form = new MultipartFormDataContent();HttpContent content = new StringContent("long text...");content.Headers.ContentType = new MediaTypeHeaderValue("text/csv");HttpContent fields = new FormUrlEncodedContent(parameters);form.Add(content, "message");form.Add(fields);response = client.PostAsync(baseUrl, form).Result;var message = response.Content.ReadAsStringAsync().Result;}它使这个 URL:POST /api/v25/upload/test HTTP/1.1这将是正确的地址:POST /api/v25/upload/test?field1=value1&field2=value2 HTTP/1.1请问代码错误在哪里?
1 回答
- 1 回答
- 0 关注
- 255 浏览
添加回答
举报
0/150
提交
取消