I want to edit an outbound payload using set-body in this way:
{"link": "http://localhost:7071/api"} to {"link":""} <- some other link
I have tried this but there is no change in outbound:
JObject inBody = context.Response.Body.As<JObject>();
string str = inBody.ToString();
var item = JObject.Parse("{ 'link': 'http://localhost:7071/api}");
item["link"] = "https://randomlink/269";
return str;
CodePudding user response:
To explain why your code does not work:
JObject inBody = context.Response.Body.As<JObject>(); //Request
payload has been parsed and stored in `inBody` variable.
string str = inBody.ToString(); //`inBody` converted to string and stored in `str` variable.
var item = JObject.Parse("{ 'link': 'http://localhost:7071/api}"); //Some other JSON parsed and stored in `item` variable
item["link"] = "https://randomlink/269"; //`item` variable updated with new value
return str; //Returning `str` variable as new body value
You never actually change value of str
to produce new body. Try:
JObject inBody = context.Response.Body.As<JObject>();
inBody["link"] = "https://randomlink/269";
return inBody.ToString();