Monday, March 28, 2022

[SOLVED] Curl URL with double quote

Issue

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.


Solution

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%26q2=b%26q3=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:%2F%2Ftarget-xxx%2Fapi%2Fv1%2Fresource%3Fq1=a%26q2=b%26q3=c"
}

If you wish path quoted

curl -v --location --request GET https://httpbin.org/get?path=\"https://target-xxx/api/v1/resource?q1=a%26q2=b%26q3=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:%2F%2Ftarget-xxx%2Fapi%2Fv1%2Fresource%3Fq1=a%26q2=b%26q3=c\""
}


Answered By - 273K
Answer Checked By - Senaida (WPSolving Volunteer)