如何使用 HTTPBuilder 发出包含德语变音符号的 REST 请求?如果我尝试使用 Postman 发出相同的请求,它会成功。当我尝试使用 Scriptrunner for Jira 使用 groovy HTTPBuilder 执行此操作时,我总是收到“错误请求”
有没有办法可以发送变音符号?
我正在尝试使用的代码:
def http = new HTTPBuilder(<Endpoint>)
def token = ""
def zulieferer = Assets.search("objectSchemaId = 5 AND objectType = Lieferant")
zulieferer.each { asset ->
try {
def name = asset.getName()
def kundennummer = asset.getString("Kundennummer")
def kreditorNummer = asset.getString("Kreditor-Nummer")
def strasse = asset.getString("Straße")
def plz = asset.getString("PLZ")
def ort = asset.getString("Ort")
def fon = asset.getString("Telefon")
def hotlineFon = asset.getString("Hotline Telefon")
def hotlineMail = asset.getString("Hotline Mail")
def homepage = asset.getString("Homepage")
def consultant = asset.getString("Consultant")
def sales = asset.getString("Sales")
if (name != null) {
name.replace("–", "-")
}
if (kundennummer != null) {
kundennummer.replace("–", "-")
}
if (kreditorNummer != null) {
kreditorNummer.replace("–", "-")
}
if (strasse != null) {
strasse.replace("–", "-")
}
if (plz != null) {
plz.replace("–", "-")
}
if (ort != null) {
ort.replace("–", "-")
}
if (fon != null) {
fon.replace("–", "-")
}
if (hotlineFon != null) {
hotlineFon.replace("–", "-")
}
if (hotlineMail != null) {
hotlineMail.replace("–", "-")
}
if (homepage != null) {
homepage.replace("–", "-")
}
if (consultant != null) {
consultant.replace("–", "-")
}
if (sales != null) {
sales.replace("–", "-")
}
def contactString = "<p>Kundennummer: ${kundennummer}</p>\n" +
"<p>Kreditor-Nummer: ${kreditorNummer}</p>\n" +
"<p>Strasse: ${strasse}</p>\n" +
"<p>PLZ: ${plz}</p>\n" +
"<p>Ort: ${ort}</p>\n" +
"<p>Telefon: ${fon}</p>\n" +
"<p>Hotline Telefon: ${hotlineFon}</p>\n" +
"<p>Hotline Mail: ${hotlineMail}</p>\n" +
"<p>Homepage: ${homepage}</p>\n" +
"<p>Consultant: ${consultant}</p>\n" +
"<p>Sales: ${sales}</p>"
try {
def jsonBody = [tenant: 1, name: name, contact: contactString, resourcetype: "ThirdParty"]
http.request(POST, JSON) { req ->
headers.'Content-Type' = 'application/json'
headers.'Authorization' = "Bearer ${token}"
body = jsonBody
response.success = { resp, json ->
// log.warn(json)
}
}
} catch (Exception ex) {
log.warn("Asset: ${name} konnte nicht angelegt werden | " + ex)
}