Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Curl URL with double quote

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.

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

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\""
}
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading