Converting MailGun cUrl to Coldfusion

偶尔善良 提交于 2020-01-05 08:56:49

问题


I'm attempting to perform actions on a Mailgun mailing list using Coldfusion.

Mailgun have supplied the following cUrl:

curl -s --user 'api:key-xxxMyAPIkeyxxx' -G \
https://api.mailgun.net/v3/lists/myList@myDomain.mailgun.org/members

I can get a good response by simply entering

https://api:key-xxxmyAPIkeyxxx@api.mailgun.net/v3/lists/myList@myDomain.mailgun.org/members

But I've had no luck converting this into a CFHTTP call:

<cfhttp url="https://api:key-xxxmyAPIkey@api.mailgun.net/v3/lists/myList@myDomain.mailgun.org/members" method="GET" result="resultName">

<cfdump var="#resultName#">

This returns a whole load of errors:

object ErrorDetail [string]
Mimetype [string] application/json Statuscode [string] 401 Unauthorized Filecontent [object]
object [empty] Responseheader [object] object Connection [string] close Content-Length [number] 0 Date [string] Mon, 10 Aug 2015 16:46:22 GMT Explanation [string] Unauthorized Content-Type [string] application/json Http_Version [string] HTTP/1.1 Www-Authenticate [string] Basic realm="MG API" Server [string] nginx/1.7.9 Status_Code [number] 401 Text [boolean] false Charset [string]
Header [string] HTTP/1.1 401 Unauthorized Content-Type: application/json Connection: close Date: Mon, 10 Aug 2015 16:46:22 GMT Www-Authenticate: Basic realm="MG API" Content-Length: 0 Server: nginx/1.7.9

Any ideas ??


回答1:


The Mailgun API says basic authentication is used. Try supplying the credentials via the username and password attributes instead of the URL:

<cfhttp url="https://api.mailgun.net/v3/lists/myList@myDomain.mailgun.org/members" 
      method="GET" 
      username="api" 
      password="key-xxxYourAPIKeyxxx"
      result="resultName" />


来源:https://stackoverflow.com/questions/31925090/converting-mailgun-curl-to-coldfusion

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!