1

I'd like to post one file and a json object to my server. Posting as a Parameter works fine, so this works:

request.AddFile ("MyPic", organisation.Pic, "Pic.png", "image/png");
request.AddParameter ("name", "test name");

But if my JSON object is something with a nested structure like:

{organisation:{
   'name':'test',
   'address':{
     'line1':'foo',
     'line2':'foo2'
   }
 }}

How do I post this, while maintaining the json structure.

If I set it in the content body i.e.:

request.AddBody (organisation);

the content is posted, but the file is not posted.

Is it possible to post both a json body and file?

4

3 回答 3

2

所以,我想出了一个适合我目的的解决方法。我一直在寻找的是对文件和相关元数据进行一次发布。在这种情况下,我将对象序列化为 JSON 字符串,将其设置为我的参数并在服务器上反序列化。这适用于我的情况,但我接受这对其他人可能并不理想。认为它可能会帮助某人。

于 2013-06-26T13:31:48.843 回答
1

不,当您使用 AddFile 时,您实际上是在向您的请求添加正文。您不能发送带有 2 个正文的请求。

于 2013-06-25T21:28:19.500 回答
0

Actually this will be possible very soon. There's a pull request on the RestSharp library that addresses this. I've started maintaining the project and will be merging it into master in the next day or so. Once there's enough stuff, I'll release a new NuGet package as well.

于 2014-10-17T18:08:20.273 回答