Where can I use variables in *.http files?

Perhaps I'm missing the right section in docs, but at https://www.jetbrains.com/help/phpstorm/exploring-http-syntax.html#using_request_vars all that's said about variables is:

A variable can hold the values for the request's host, port, and path, query parameter or value, header value, or arbitrary values used inside the request body or in an external file.

However, in practice I see that some variables are parsed and some are not:

PATCH http://example.com/api/v1/foo/{{notParsed}}
# Invalid URI because of unsubstituted variable 'notParsed'
Authorization: Bearer {{thisWorksFine}}
Content-Type: application/json

{
"foo": "{{thisWorksToo}}",
"{{notParsedEither}}": ""
}

Am I missing something? What are the rules?

评论操作 固定链接

I realise I omitted a bit of context (I'm using the client object to populate some global/session variables to be used later on).

Never mind, my diagnostics were totally flawed. Variable placeholders apparently work in every* context, and that's why documentation doesn't need to mention it. What happened was that I was parsing a JSON response and I got some paths wrong, so some variables where "randomly" not set.

(*) The exception seem to be HTTP header names, but I'm still not 100% sure that my test and web server settings are fully correct. (And it's not a feature I actually need).

### 400 Bad Request
GET {{baseUrl}}
Test-{{requestId}}: Static Value

Edit: definitively, this seems to be the only exception. Even auto-completion fails to work in header names. As said, no problem.

### 400 Bad Request
GET http://example.com/
Test-{{$randomInt}}: Static Value
1

请先登录再写评论。