0

我有这个代码:

$arr = array("id" => 3);

$response = \Httpful\Request::get($restapiUrl)
            ->sendsJson()
            ->expectsJson()
            ->body(json_encode($arr))
            ->send();

对我的 API 的每次调用都以错误 404 失败告终:错误请求。我必须通过 php.ini 的请求正文发送参数。

我的api代码:

[HttpGet]
[Route("api/MyController/GetProduct")]
public IHttpActionResult GetProduct([FromBody] int id)
{
    var product = products.FirstOrDefault((p) => p.Id == id);
    if (product == null)
    {
        return NotFound();
    }
    return Ok(product);
}

我错过了什么?

4

0 回答 0