如何在groovy中指定请求中的内容类型?
我正在尝试使用 groovy httpbuilder 向 Microsoft Exchange Web 服务(EWS)发布帖子。我的问题是,我无法设置正确的请求内容类型。图书馆似乎在这里有自己的想法。
有人有想法吗?
干杯, 斯蒂芬
这是我的代码:
url = "http://exchangeserver/ews/Exchange.asmx"
p_body = "<soap request >...";
p_contentType = "text/xml; charset=utf-8"
customHeaders = ["SOAPAction":"LONG_URL"]
def http = new HTTPBuilder(url);
http.auth.basic(authMap.username, authMap.password)
// contentType: p_contentType,
http.request( POST )
{
contentType = ContentType.TEXT // We dont want to get the response parsed
headers['Accept'] = "*/*"; // Just make sure we accept everything
// Support additional headers
for (x in customHeaders) {
headers[x] = customHeaders[x]
}
/// Exchange expects "text/xml; charset=utf-8" and nothing else :(
// This sends text/plain
// body = p_body
// requestContentType = p_contentType
// This sends application/xml, not my "text/xml; charset=utf-8" content-type.
send p_contentType, p_body
// a successfull request should be "logged" ;)
response.success = { resp, xml ->
println xml
}
}
i'm trying to use the groovy httpbuilder to make a post to the microsoft exchange webservice (EWS). My problem is, I'm unable to set the proper request content-type. The library seems to have its own mind here.
Does anyone have an idea?
Cheers,
Stephan
Here is my code:
url = "http://exchangeserver/ews/Exchange.asmx"
p_body = "<soap request >...";
p_contentType = "text/xml; charset=utf-8"
customHeaders = ["SOAPAction":"LONG_URL"]
def http = new HTTPBuilder(url);
http.auth.basic(authMap.username, authMap.password)
// contentType: p_contentType,
http.request( POST )
{
contentType = ContentType.TEXT // We dont want to get the response parsed
headers['Accept'] = "*/*"; // Just make sure we accept everything
// Support additional headers
for (x in customHeaders) {
headers[x] = customHeaders[x]
}
/// Exchange expects "text/xml; charset=utf-8" and nothing else :(
// This sends text/plain
// body = p_body
// requestContentType = p_contentType
// This sends application/xml, not my "text/xml; charset=utf-8" content-type.
send p_contentType, p_body
// a successfull request should be "logged" ;)
response.success = { resp, xml ->
println xml
}
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
好吧,阅读和调试代码,我发现这是我当前的解决方法/解决方案。没有我希望的那么美丽:
Well, reading and debugging the code, I found this to be my current workaround / solution. Not as beautifull as I hoped: