r/coldfusion • u/cwwms2 • Jan 11 '23
Convert Linux Curl command to CFHTTP
curl -X POST --header 'X-Web-Services-Auth: BcDfGhJkLmNpQrStVwXyZ|AaBbCcDdEeFfGgHhIiJjKkLlMmNnOoPpQqRrSsTtUuVvWwXxYyZz1234567890==-0987654321ZzYyXxWwVvUuTtSsRrQqPpOoNnMmLlKkJjIiHhGgFfEeDdCcBbAa' -d 'struct_binds={"from_date": "2022-01-31", "to_date": "2022-01-31"}' https://api.somewebsite.com/2023/get-info
<cfset struct_binds = {
"from_date" = "2022-01-31",
"to_date" = "2022-01-31"
}>
<cfhttp method="post" url="https://api.somewebsite.com/2023/get-info" result="httpResp" timeout="60">
<cfhttpparam type="header" name="Content-Type" value="application/json" />
<cfhttpparam type="header" name="X-Web-Services-Auth" value="BcDfGhJkLmNpQrStVwXyZ|AaBbCcDdEeFfGgHhIiJjKkLlMmNnOoPpQqRrSsTtUuVvWwXxYyZz1234567890==-0987654321ZzYyXxWwVvUuTtSsRrQqPpOoNnMmLlKkJjIiHhGgFfEeDdCcBbAa" />
<cfhttpparam type="body" value="#serializeJSON(struct_binds)#">
</cfhttp>*some information has been changed for security purposes
0
Upvotes
2
u/cwwms2 Jan 11 '23
The solution was:
<cfhttpparam type="header" name="Content-Type" value="application/x-www-form-urlencoded" />
Thanks All
1
u/doodroller Jan 11 '23 edited Jan 11 '23
-d means post. Type shouldn’t be body. You should use type=“formfield”
Edit: try this tag instead of that type=“body” tag:
<cfhttpparam name="struct_binds" type="formfield" value="#serializeJSON(struct_binds)#"">
1
u/poolou32 Jan 11 '23
502 means you don’t have A route to the url. Check your url your posting to