laravel-shift / curl-converter

Online tool to convert `curl` requests to Laravel `Http` requests
MIT License
88 stars 10 forks source link

Dealing with POST data with multiple keys that are the same value. #16

Closed jonnywilliamson closed 2 years ago

jonnywilliamson commented 2 years ago

Hi there, this is a really useful project thank you!

I've just tried with one of my more troublesome POST queries I have to make and I'm having a problem getting it to convert.

I need to make a POST request to a URL with the following as the payload. This is taken directly as a copy from Chrome using devtools.

The Raw format

Print=Print&selection=aerodromeOrder&aerodrome=eick&Basket=false&icao=eick&check=on&order=eickei+&order=f1780614+&order=f1738132+&order=b1738132+&order=f1928002+&order=f1736502+&order=b1736502+&order=f1736540+&order=f1736509+&order=b1736509+&order=f1736520+&order=b1736520+&order=f1736511+&order=b1736511+&order=f1736512+&order=b1736512+&order=f1736518+&order=b1736518+&order=f1736521+&order=b1736521+&order=f1736523+&order=f1736513+&order=b1736513+&order=f1736515+&order=b1736515+&order=f1736536+&order=b1736536+&order=f1896451+&order=b1896451+&order=f1736525+&order=b1736525+&order=f1758356+

Image from chrome dev tools:

CleanShot 2022-10-13 at 08 36 30

As you can see there are multiple order keys in the data payload.

However when I try and use this package to convert this to Laravel HTTP format, only the last order key survives.

CleanShot 2022-10-13 at 08 37 06

Whats the best way to deal with multiple keys having the same name?

This was the original request I tried to convert, I've just removed some excessive headers.

curl 'https://viewer.flightsupport.com/servlet/PrintServlet' \
  -H 'Content-Type: application/x-www-form-urlencoded' \
  -H 'Cookie: REDACTED' \
  -H 'Origin: https://viewer.flightsupport.com' \
  -H 'Pragma: no-cache' \
  -H 'Referer: https://viewer.flightsupport.com/frames/home.jsp' \
  -H 'Sec-Fetch-Dest: document' \
  -H 'Sec-Fetch-Mode: navigate' \
  -H 'Sec-Fetch-Site: same-origin' \
  -H 'Sec-Fetch-User: ?1' \
  -H 'Upgrade-Insecure-Requests: 1' \
  -H 'User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/106.0.0.0 Safari/537.36' \
  --data-raw 'Print=Print&selection=aerodromeOrder&aerodrome=eick&Basket=false&icao=eick&check=on&order=eickei+&order=f1780614+&order=f1738132+&order=b1738132+&order=f1928002+&order=f1736502+&order=b1736502+&order=f1736540+&order=f1736509+&order=b1736509+&order=f1736520+&order=b1736520+&order=f1736511+&order=b1736511+&order=f1736512+&order=b1736512+&order=f1736518+&order=b1736518+&order=f1736521+&order=b1736521+&order=f1736523+&order=f1736513+&order=b1736513+&order=f1736515+&order=b1736515+&order=f1736536+&order=b1736536+&order=f1896451+&order=b1896451+&order=f1736525+&order=b1736525+&order=f1758356+'
jasonmccreary commented 2 years ago

Support for --data-raw is in progress.

However, this is a bit more of a PHP thing. To pass multiple order items, you'd have to use the array notation, i.e. order[]. Otherwise, the last passed order is used.