Piezīmes
Lai piekļūtu šai lapai, ir nepieciešama autorizācija. Varat mēģināt pierakstīties vai mainīt direktorijus.
Lai piekļūtu šai lapai, ir nepieciešama autorizācija. Varat mēģināt mainīt direktorijus.
At a glance
Goal: Return binary files as mock responses
Time: 5 minutes
Plugins: MockResponsePlugin
Prerequisites: Set up Dev Proxy
For some requests, you might want to respond with binary data like documents or images.
In Dev Proxy, you can define a binary response by setting the response.body to a string value that starts with @ followed by file path relative to the current working directory, for example:
File: mocks.json
{
"$schema": "https://raw.githubusercontent.com/dotnet/dev-proxy/main/schemas/v2.0.0/mockresponseplugin.mocksfile.schema.json",
"mocks": [
{
"request": {
"url": "https://graph.microsoft.com/v1.0/users/*/photo/$value",
"method": "GET"
},
"response": {
"body": "@picture.jpg",
"headers": [
{
"name": "content-type",
"value": "image/jpeg"
}
]
}
}
]
}
When you call GET https://graph.microsoft.com/v1.0/users/ben@contoso.com/photo/$value, you get the image stored in the picture.jpg file in the current directory.
Caution
If you're using the command line to execute the HTTP request, ensure that you have correctly escaped the dollar sign. See Why is proxy not mocking my binary response.
Next step
Learn more about the MockResponsePlugin.
Samples
See also the related Dev Proxy samples: