Skip to content

Commit 304f975

Browse files
committed
updated with Mahsa's corrected example
1 parent 3ad2a90 commit 304f975

File tree

1 file changed

+5
-4
lines changed

1 file changed

+5
-4
lines changed

articles/api-management/set-body-policy.md

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -250,14 +250,15 @@ The following example uses the `AsFormUrlEncodedContent()` expression to access
250250
</set-body>
251251
```
252252

253-
### Transform JObject body to URL-encoded form data
254-
The following example accesses the request body as a JObject and transforms it to URL-encoded form data (content type `application/x-www-form-urlencoded`). We are preserving the original request body so that we can access it later in the pipeline.
253+
### Access and return body as URL-encoded form data
254+
The following example uses the `AsFormUrlEncodedContent()` expression to access the request body as URL-encoded form data (content type `application/x-www-form-urlencoded`), adds data to the payload, and returns URL-encoded form data. Since we are not reserving the original request body, accessing it later in the pipeline will result in an exception.
255255

256256
```xml
257257
<set-body
258258
@{ 
259-
JObject inBody = context.Request.Body.As<JObject>(preserveContent: true); 
260-
return inBody.ToFormUrlEncodedContent(); 
259+
var body = context.Request.Body.AsFormUrlEncodedContent();
260+
body ["newKey"].Add ("newValue");
261+
return body.ToFormUrlEncodedContent(); 
261262
262263
</set-body>
263264
```

0 commit comments

Comments
 (0)