gpt4 book ai didi

grails - 从 grails 向 mailchimp 2.0 发送 post 请求

转载 作者:行者123 更新时间:2023-12-02 15:27:40 24 4
gpt4 key购买 nike

目前,我正在将我的 grails 项目与 mailchimp 2.0 API 集成(我们目前使用来自 grails-mailchimp 插件的 1.2 版)
当我向 mailchimp 端点发送带有 json 数据的发布请求时,我总是收到此错误“HTTP/1.1 302 已临时移动”。我该如何解决?

这是我使用 HTTPBuilder 的代码

def twitter = new RESTClient( "https://us4.api.mailchimp.com/2.0/lists/member-info.json")
def resp = twitter.post(
path : '/',
body : body1,
requestContentType : ContentType.JSON )

assert resp.status == 200

我的日志记录:
http.RESTClient POST https://us4.api.mailchimp.com/
conn.BasicClientConnectionManager Get connection for route {s}->https://us4.api.mailchimp.com
conn.DefaultClientConnectionOperator Connecting to us4.api.mailchimp.com:443
protocol.RequestAddCookies CookieSpec selected: best-match
protocol.RequestAuthCache Auth cache not set in the context
protocol.RequestTargetAuthentication Target auth state: UNCHALLENGED
protocol.RequestProxyAuthentication Proxy auth state: UNCHALLENGED
client.DefaultHttpClient Attempt 1 to execute request
conn.DefaultClientConnection Sending request: POST / HTTP/1.1
http.wire >> "POST / HTTP/1.1[\r][\n]"
http.wire >> "Accept: */*[\r][\n]"
http.wire >> "Content-Length: 106[\r][\n]"
http.wire >> "Content-Type: application/json[\r][\n]"
http.wire >> "Host: us4.api.mailchimp.com[\r][\n]"
http.wire >> "Connection: Keep-Alive[\r][\n]"
http.wire >> "[\r][\n]"
http.headers >> POST / HTTP/1.1
http.headers >> Accept: */*
http.headers >> Content-Length: 106
http.headers >> Content-Type: application/json
http.headers >> Host: us4.api.mailchimp.com
http.headers >> Connection: Keep-Alive
http.wire >> "{"id":"xxx","emails":[{"email":"xxx"}],"apikey":"xxx-us4"}"
http.wire << "HTTP/1.1 302 Moved Temporarily[\r][\n]"
http.wire << "Server: nginx[\r][\n]"
http.wire << "Content-Type: text/html; charset=UTF-8[\r][\n]"
http.wire << "Content-Length: 1[\r][\n]"
http.wire << "Location: http://apidocs.mailchimp.com/[\r][\n]"
http.wire << "Date: Sun, 10 Aug 2014 09:22:24 GMT[\r][\n]"
http.wire << "Connection: keep-alive[\r][\n]"
http.wire << "[\r][\n]"
conn.DefaultClientConnection Receiving response: HTTP/1.1 302 Moved Temporarily
http.headers << HTTP/1.1 302 Moved Temporarily
http.headers << Server: nginx
http.headers << Content-Type: text/html; charset=UTF-8
http.headers << Content-Length: 1
http.headers << Location: http://apidocs.mailchimp.com/
http.headers << Date: Sun, 10 Aug 2014 09:22:24 GMT
http.headers << Connection: keep-alive
client.DefaultHttpClient Connection can be kept alive indefinitely
http.RESTClient Response code: 302; found handler: org.codehaus.groovy.runtime.MethodClosure@30198ecc
http.RESTClient Parsing response as: text/html
http.wire << "[\n]"
conn.BasicClientConnectionManager Releasing connection org.apache.http.impl.conn.ManagedClientConnectionImpl@5dee0bbf
conn.BasicClientConnectionManager Connection can be kept alive indefinitely
http.RESTClient Parsed data to instance of: class groovy.util.slurpersupport.NodeChild

好像我发送的是 http,而不是 https(因为代码 302 Moved Temporarily only for HTTP 协议(protocol)),不是吗?如果是,我该如何解决?

最佳答案

最后我可以找到一种发送到mailchimp的方法,它只是跟随httpbuilder tutorial

    def emails = []
emails.add(['email': email_address])
def body1 = ['id' : id, 'emails' : emails, 'apikey': apiKey]
def http = new HTTPBuilder("https://us4.api.mailchimp.com/2.0/lists/member-info.json")
http.request(Method.POST, ContentType.JSON ) { req ->
body = body1
response.success = { resp, json ->
assert resp.statusLine.statusCode == 200
println json
}
}

关于grails - 从 grails 向 mailchimp 2.0 发送 post 请求,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25227261/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com