GROOVY中的httppost
我正在拼命地将这段python代码翻译成groovy,但我找不到正确的解决方案 如果有人能帮我一点忙,那就太好了。:)GROOVY中的httppost,groovy,soap,http-post,soapui,camunda,Groovy,Soap,Http Post,Soapui,Camunda,我正在拼命地将这段python代码翻译成groovy,但我找不到正确的解决方案 如果有人能帮我一点忙,那就太好了。:) #/usr/bin/env蟒蛇3 #编码:utf-8 导入请求 url=”http://localhost:8088/mockServiceSoapBinding" xml=“” 登录 登录123 ''' headers={'content-type':'text/xml;charset=UTF-8','Accept Encoding':'gzip,deflate'} r1=r
#/usr/bin/env蟒蛇3
#编码:utf-8
导入请求
url=”http://localhost:8088/mockServiceSoapBinding"
xml=“”
登录
登录123
'''
headers={'content-type':'text/xml;charset=UTF-8','Accept Encoding':'gzip,deflate'}
r1=requests.post(url,data=xml,headers=headers,auth=('user','pass'))
打印(r1.文本)
从Groovy进行HTTP POST调用可以通过初始化URL连接来完成
以下是一个工作示例:
url='1〕http://localhost:8088/mockServiceSoapBinding'
def username='user'
def password='pass'
xml=“”
登录
登录123
'''
def connection=新URL(URL).openConnection()
connection.setRequestMethod('POST'))
//设置标题
connection.setRequestProperty('Content-Type','text/xml;charset=UTF-8')
setRequestProperty('Accept-Encoding','gzip,deflate')
如果(用户名和密码){
字符串userCredentials=username+':'+密码
字符串basicAuth='Basic'+Base64.getEncoder().encode(userCredentials.getBytes())
connection.setRequestProperty('Authorization',basicAuth)
}
connection.doOutput=true
connection.outputStream.write(xml.getBytes('UTF-8'))
println“XX:连接”
connection.connect()
println“XX:获取内容”
def text=connection.content.text
println(文本)
在搜索框中键入groovy http post
,您将有很多示例…请添加您尝试的代码以及失败的原因(例如错误、堆栈跟踪、日志等),以便我们对其进行改进。
#! /usr/bin/env python3
# coding: utf-8
import requests
url = "http://localhost:8088/mockServiceSoapBinding"
xml = '''<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:sam="http://www.soapui.org/sample/">
<soapenv:Header/>
<soapenv:Body>
<sam:login>
<username>Login</username>
<password>Login123</password>
</sam:login>
</soapenv:Body>
</soapenv:Envelope>'''
headers = {'content-type': 'text/xml;charset=UTF-8', 'Accept-Encoding': 'gzip,deflate'}
r1 = requests.post(url, data=xml, headers=headers, auth=('user', 'pass'))
print(r1.text)