我有以下控制器:
public class ValuesController : ApiController
{
// POST api/values
public IHttpActionResult Post(string filterName)
{
return new JsonResult<string>(filterName, new JsonSerializerSettings(), Encoding.UTF8, this);
}
}
Run Code Online (Sandbox Code Playgroud)
WebApi配置
config.Routes.MapHttpRoute(
name: "DefaultApi",
routeTemplate: "api/{controller}/{id}",
defaults: new { id = RouteParameter.Optional });
Run Code Online (Sandbox Code Playgroud)
我使用这个js代码来调用api
$.ajax(
{
url: "/api/values/",
type: "POST",
dataType: 'json',
data: { filterName: "Dirty Deeds" },
success: function (result) {
console.log(result);
},
error: function (xhr, status, p3, p4) {
var err = "Error " + " " + status + " " + p3; …Run Code Online (Sandbox Code Playgroud) 我正在使用 Postman 测试在线上传到 SharePoint 的文件。在我的 post 请求中,我将 body 设置为 form-data 并添加一个带有名为 a.txt 的文本文件的文件参数。文本文件包含文本
one
two
three
Run Code Online (Sandbox Code Playgroud)
当我执行请求时,我的文件已上传,但是当我打开文件时,内容是
----------------------------235004993628819232914336
Content-Disposition: form-data; name="file"; filename="a.txt"
Content-Type: text/plain
one
two
three
----------------------------235004
Run Code Online (Sandbox Code Playgroud)
我尝试将 Content-Type 标头设置为
application/x-www-form-urlencoded 或 multipart/form-data
但没有运气