我需要使用 POST JSON 检查后端,但找不到这样做的方法。以下是有效的 curl POST。如何在 HAPROXY httpchk 中执行此操作
curl -H "Content-Type: application/json" -X POST -d '["za.co.calculator",{"grossMonthlyIncome":["java.math.BigDecimal",100000.00],"loanTermYears":20,"interestRate":["java.math.BigDecimal",10.25]}]' https://servername/calculator/api/calculator/calculateMaximumLoanAmount
我的 HaProxy 配置是:
option httpchk POST /calculator-service-2.0/api/calculator/calculateMaximumLoanAmount HTTP/1.1\r\nContent-Type: application/json\r\nContent-Length: 174\r\n\r\n{"za.co.fnb.soa.calculator.dto.S_MaxBondInputInfo",{"grossMonthlyIncome":["java.math.BigDecimal",100000.00],"loanTermYears":20,"interestRate":["java.math.BigDecimal",10.25]}}
答案1
如果你能展示一下你尝试过的方法就好了前你来这里寻求帮助,但无论如何......我没有测试以下内容,但这可能作为你的起点:
option httpchk POST /calculator/api/calculator/calculateMaximumLoanAmount HTTP/1.1\r\nContent-Type:\ application/json\r\nContent-Length:\ 144\r\n\r\n["za.co.calculator",{"grossMonthlyIncome":["java.math.BigDecimal",100000.00],"loanTermYears":20,"interestRate":["java.math.BigDecimal",10.25]}]
注意:您可能需要修复Content-Lengtt
参数和特殊字符、换行符等的转义。
答案2
嗨,我终于让它工作了。我需要添加Host:\ haproxyservices
option httpchk POST /calculator/api/calculator/calculateMaximumLoanAmount HTTP/1.1\r\nHost:\ haproxyservices\r\nContent-Type: application/json\r\nContent-Length:\ 174\r\n\r\n{"za.co.calculator",{"grossMonthlyIncome":["java.math.BigDecimal",100000.00],"loanTermYears":20,"interestRate":["java.math.BigDecimal",10.25]}}
谢谢您的帮助。