【问题标题】:How to make a Request with a Image using postman如何使用邮递员使用图像发出请求
【发布时间】:2017-10-29 20:46:57
【问题描述】:

在我的 WebApi 项目中,这是我的 Current

http://localhost:52494/api/v1/Register/RegisterUser

而且参数是一个模型:

public class DataUserModel
{
    public string Gender { get; set; }
    public int PhoneNumber { get; set; }
    public byte[] ProfileImage { get; set; }
}

如何设置 Postman 以使用二进制图像和 JSON 格式的其他属性发送此请求!我通常这样做:

Content-Type:application/json
{
   "Gender":'F',
   "PhoneNumber":99999999,
}

【问题讨论】:

    标签: asp.net-web-api postman


    【解决方案1】:

    这里基本上有两种选择:

    • 在 2 个单独的请求中发送 JSON 和二进制数据。我更喜欢这种方法,保持它的简洁性和可读性。
    • 将 JSON 和 Binary 合并到一个请求中。这有点复杂,您需要使用 Content-Type: multipart/form-data;来实现这个结果。

    看看http://blog.marcinbudny.com/2014/02/sending-binary-data-along-with-rest-api.html,它详细描述了这两种情况。

    在 Postman (Pseudo Code) 中,您将有如下内容:

    POST http://localhost:52494/api/v1/Register/RegisterUser HTTP/1.1
    
    Content-Type: multipart/form-data; boundary="01ead4a5-7a67-4703-ad02-589886e00923"
    Host: 127.0.0.1:53908
    Content-Length: 707419
    
    
    --01ead4a5-7a67-4703-ad02-589886e00923
    Content-Type: application/json; charset=utf-8
    Content-Disposition: form-data; name=imageset
    
    
    {"Gender":"F", "PhoneNumber" : 99999999}
    --01ead4a5-7a67-4703-ad02-589886e00923
    Content-Type: image/jpeg
    Content-Disposition: form-data; name=image0; filename=Small-Talk-image.jpg
    
    
    
    {YOUR IMAGE CONTENT HERE}
    --01ead4a5-7a67-4703-ad02-589886e00923
    Content-Type: image/jpeg
    Content-Disposition: form-data; name=image2; filename=url.jpg
    

    【讨论】:

      猜你喜欢
      • 2021-12-14
      • 2020-11-15
      • 2021-10-15
      • 2018-07-16
      • 1970-01-01
      • 2018-10-16
      • 2022-10-18
      • 1970-01-01
      • 2016-04-03
      相关资源
      最近更新 更多