Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
888 views
in Technique[技术] by (71.8m points)

http - Getting Basic Authentication to work with ColdFusion

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="[email protected]">
    <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 "[email protected]" 
    -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.

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

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>

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...