用Fiddler用属性[FromForm]填充参数 [英] Filling Parameter with Attribute [FromForm] with Fiddler

查看:54
本文介绍了用Fiddler用属性[FromForm]填充参数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想用提琴手测试以下方法(由招摇产生):

I want to test the following method (generated by swagger) with fiddler:

[HttpPost]
[Route("/webservice/images")]
[SwaggerOperation("UploadImage")]
[SwaggerResponse(200, type: typeof(ResourceIdEntry))]
public virtual IActionResult UploadImage([FromForm] Stream image)
{
    return new ObjectResult();
}

我将Fiddler配置为使用标头将POST发送到 http://localhost:50352/webservice/images

I configure Fiddler to send a POST to http://localhost:50352/webservice/images with the Header

Content-Type: multipart/form-data; boundary=-------------------------acebdf13572468
User-Agent: Fiddler
Host: localhost:50352
Content-Length: 12931

和身体

---------------------------acebdf13572468
Content-Disposition: form-data; name="image"; filename="Test.tif"
Content-Type: image/tiff

<@INCLUDE *C:\...\Test.tif*@>
---------------------------acebdf13572468--

,但是甚至没有调用UploadImage,我只返回了500.如果删除image参数,则该方法至少会被调用.我必须如何配置提琴手才能正确解决呼叫?

but UploadImage is not even called and I just get a 500 returned. If I remove the image parameter, the Method gets at least called. How do I have to configure fiddler so that the call is resolved correctly?

推荐答案

查看以下有关使用Web API上传文件的帖子-

Checkout the following post around uploading file with web api - https://docs.microsoft.com/en-us/aspnet/web-api/overview/advanced/sending-html-form-data-part-2

没有内置的媒体格式化程序可用于处理多部分表单帖子.但是,这并不能阻止您编写自己的代码,因此可以将相同的逻辑应用于多个操作,这是自定义格式化程序的主要示例- https://gist.github.com/Danielku15/bfc568a19b9e58fd9e80

There is no built in media formatter for dealing with multi part form posts. However this is nothing stopping you writing your own so the same logic can be applied to multiple actions, here is a gist example of a custom formatter - https://gist.github.com/Danielku15/bfc568a19b9e58fd9e80

这篇关于用Fiddler用属性[FromForm]填充参数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆