![](/img/trans.png)
[英]Trying to upload a file from controller using HttpWebRequest method to API Action that has an argument of [FromForm] IFormFile file receives null
[英]How to execute an API PUT method that has [[FromForm]] argument in powershell
我的API有一個更新預留對象的PUT方法。
[HttpPut]
public Reservation Put([FromForm] Reservation res) =>
repository.UpdateReservation(res);
我只想知道如何使用Visual Studio中的包管理器控制台在powershell中執行此方法?
注意,此方法具有[FromForm]模型綁定方法。 所以我必須在表單數據中發送Reservation數據。
我知道如果這個方法有[FromBody]屬性而不是[FromForm],那么我可以在powershell上執行以下命令。
Invoke-RestMethod http://localhost:8888/api/Reservation -Method PUT
-Body (@{Id="5"; Name="Mary"; StartLocation="Tokyo"; EndLocation="Abu Dhabi"} |
ConvertTo-Json) -ContentType "application/json"
但我想知道[FromForm]屬性的命令是什么,請幫忙嗎?
FromForm屬性用於來自內容類型application/x-www-url-formencoded
發送的提交表單的傳入數據。 因此,將contentType設置為application/x-www-url-formencoded
。
試試吧
$url = "http://localhost:8888/api/Reservation";
$body = @{Id="5"; Name="Mary"; StartLocation="Tokyo"; EndLocation="Abu Dhabi"};
Invoke-RestMethod -Uri $ClipsURL -Body $body -Method Put -ContentType "application/x-www-form-urlencoded"
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.