我在与Attask的项目中苦苦挣扎。 我的目标是使用自定义表单数据更新项目的alignmentValues。 我已经能够创建新的对齐值来更新,但我无法使用put方法执行它... 我想要执行的请求是
PUT /attask/api/project/4c7...?updates=
{
alignmentValues: [
{
scoreCardOptionID: "2222...54d0",
scoreCardQuestionID : "8897...54d1",...
},....
]
}
我的代码段是
var request = new RestRequest("project/{id}", Method.PUT);
request.AddUrlSegment("id", pid);
request.RequestFormat = DataFormat.Json;
JObject _putData = new JObject();
_putData.Add("alignmentValues",newAnswers);
对于更新对象,我尝试了几种组合
request.AddParameter("updates",_putData,ParameterType.RequestBody); //no effect
request.AddBody(new {name = "updates", value = _putData}); //no effect
通过这种身体方法,我甚至无法更新项目名称。 但是当我提供参数作为查询字符串时,它成功更新了名称,但由于网址变得太大而导致对齐值失败
var request = new RestRequest("project/{id}?updates=" + _putData , Method.PUT);
如果_putData很小,则上述工作...如name =" TEST" ..但是对于大型json数组失败..
有关如何使用addbody / addobject / addjsonobject / addparameter更新值的任何建议......因为我需要在体内发送请求,因为它的大小......
提前致谢。
答案 0 :(得分:0)
Well this is not an answer but I made it to work by fluke.. SO the main problem still remains..I can't use body with PUT request..Even if I use its shows no result..so I had to go with query string only... Now for my problem on big parameters in the query string, I was sending the whole alignmentvalues object where I had to update only two fields within that object. So in a trial and error approach i only passed three fields within the object - answer ID and two fields to be updated...And it reduced the query string size and fortunately for me it worked..