Home > Net >  Curl URL with double quote
Curl URL with double quote

Time:02-23

I'm trying to formulate URL string in CURL request as:

curl -v --location --request GET "https://proxy-xxx.execute-api.ap-southeast-1.amazonaws.com/dev/proxy?path=\"https://target-xxx/api/v1/resource?q1=a&q2=b&q3=c\""

where I will pass "https://target-xxx/api/v1/resource?q1=a&q2=b&q3=c\" as query string to path variable in double quote.

Tested on API gateway console with path="https://target-xxx/api/v1/resource?q1=a&q2=b&q3=c" works fine.

However CURL hit bad request 400, and aws api gateway don't have received. I believe URL syntax problem.

CodePudding user response:

Quotations marks in the URL grammar do nothing special, do not mean a string literal. The first " does not mark unescaped string begin and the second " does not mark unescaped string end. You should url encode & characters to avoid splitting query params.

curl -v --location --request GET https://httpbin.org/get?path="https://target-xxx/api/v1/resource?q1=a&q2=b&q3=c"

Response:

{
  "args": {
    "path": "https://target-xxx/api/v1/resource?q1=a&q2=b&q3=c"
  },
  "headers": {
    "Accept": "*/*",
    "Host": "httpbin.org",
    "User-Agent": "curl/7.79.1",
    "X-Amzn-Trace-Id": "Root=1-6215a80a-5e94b80531a2f4076f84342e"
  },
  "url": "https://httpbin.org/get?path=https://target-xxx/api/v1/resource?q1=a&q2=b&q3=c"
}

If you wish path quoted

curl -v --location --request GET https://httpbin.org/get?path=\"https://target-xxx/api/v1/resource?q1=a&q2=b&q3=c\"

Response:

{
  "args": {
    "path": "path": "\"https://target-xxx/api/v1/resource?q1=a&q2=b&q3=c\""
  },
  "headers": {
    "Accept": "*/*",
    "Host": "httpbin.org",
    "User-Agent": "curl/7.79.1",
    "X-Amzn-Trace-Id": "Root=1-6215a9c5-11a283486ad54eb96c499bc7"
  },
  "url": "https://httpbin.org/get?path=\"https://target-xxx/api/v1/resource?q1=a&q2=b&q3=c\""
}
  • Related