将含数组参数的PHP POST cURL请求转换为cURL命令行
Got it, let's turn your PHP array-based POST request into a usable command-line cURL command. I'll break this down clearly for you:
Step 1: Map the PHP Array to JSON Payload
Since your data includes a nested price sub-array, using JSON is the cleanest approach (it mirrors the PHP array structure perfectly). Here's the equivalent JSON:
{ "vehicleClass": "Car", "category": "Van", "make": "RENAULT", "model": "Scenic", "modelDescription": "Turbopoooower", "firstRegistration": "201606", "mileage": "500", "damageUnrepaired": true, "condition": "USED", "internalNumber": "12", "price": { "consumerPriceGross": "5400" } }
Step 2: Full cURL Command
Here's the complete command-line cURL call that matches your PHP code. I've included placeholders for your proxy and auth values, plus notes on what to adjust:
curl -X POST \ -H "Content-Type: application/json" \ --proxy PROXY_MOBILE_DE:PROXY_PORT_MOBILE_DE \ --proxy-user LOGINPASSWD_MOBILE_DE \ -d '{ "vehicleClass": "Car", "category": "Van", "make": "RENAULT", "model": "Scenic", "modelDescription": "Turbopoooower", "firstRegistration": "201606", "mileage": "500", "damageUnrepaired": true, "condition": "USED", "internalNumber": "12", "price": { "consumerPriceGross": "5400" } }' \ https://your-target-api-url.com
Key Details to Adjust:
- Replace
https://your-target-api-url.comwith the actual URL you're sending the request to. - If your
LOGINPASSWD_MOBILE_DEis in the formatusername:password, it'll work directly with--proxy-user. If not, adjust it to match your proxy's auth requirements. - If you're using environment variables for proxy values (like in your PHP code), you can swap them in directly (e.g.,
$PROXY_MOBILE_DEinstead of the literal string).
Alternative: Form-Encoded Data (If Required)
If the API expects application/x-www-form-urlencoded instead of JSON, you'd format the data like this (note how nested arrays use bracket notation):
curl -X POST \ --proxy PROXY_MOBILE_DE:PROXY_PORT_MOBILE_DE \ --proxy-user LOGINPASSWD_MOBILE_DE \ -d 'vehicleClass=Car' \ -d 'category=Van' \ -d 'make=RENAULT' \ -d 'model=Scenic' \ -d 'modelDescription=Turbopoooower' \ -d 'firstRegistration=201606' \ -d 'mileage=500' \ -d 'damageUnrepaired=true' \ -d 'condition=USED' \ -d 'internalNumber=12' \ -d 'price[consumerPriceGross]=5400' \ https://your-target-api-url.com
But JSON is almost always better for nested data structures like yours, so I'd stick with the first option unless the API specifically requires form-encoded data.
内容的提问来源于stack exchange,提问作者denimb

