7

I am trying to send an authenticated POST request using ColdFusion, but for some reason, the server is rejecting the request as unauthorized. I have verified that the credentials are correct.

<cfhttp url="https://api.juspay.in/order/create" method="POST"  
    username="320EABE1225D45E6B13DF5D3D2BBDB80" password="">
    <cfhttpparam name="amount" type="formField" value="10">
    <cfhttpparam name="order_id" type="formField" value="cfhttp_test_order_001">
    <cfhttpparam name="customer_id" type="formField" value="10">
    <cfhttpparam name="customer_email" type="formField" value="user@mail.com">
    <cfhttpparam name="customer_phone" type="formField" value="1122112211">
    <cfhttpparam name="description" type="formField" value="test">
</cfhttp>

Same thing works in curl. For instance

curl https://api.juspay.in/order/create \
    -u 320EABE1225D45E6B13DF5D3D2BBDB80: \
    -d "amount=10" \
    -d "order_id=curl_test_order_001" \
    -d "customer_id=10" \
    -d "customer_email=user@mail.com" \
    -d "customer_phone=1122112211" \
    -d "description=test" 

The above curl command return HTTP 200 which is what I am trying to achieve. I am unable to figure out what I am missing in the ColdFusion code.

Ram
  • 293
  • 2
  • 7
  • By any chance do you work with [nikhil-reddy](http://stackoverflow.com/users/2278072/nikhil-reddy) and [Reload](http://stackoverflow.com/users/3870684/reload) who've both already asked the identical question? – duncan Jul 24 '14 at 12:38
  • Yes Duncan. We got the solution just a while back. – Ram Jul 24 '14 at 12:49
  • 2
    One of you should post it as an answer to your own question :-) – duncan Jul 24 '14 at 12:52

1 Answers1

14

The following actually worked. Please consider this answered:

<cfhttp method="post" url="https://api.juspay.in/order/create" result="result">
    <cfhttpparam type="header" name="Authorization" value="Basic #ToBase64("320EABE1225D45E6B13DF5D3D2BBDB80:")#" />
    <cfhttpparam type="formfield" name="amount" value="10" />
</cfhttp>
Ram
  • 293
  • 2
  • 7