我有問題將json參數傳遞給web操作。我知道,在網絡行動工作在指定的URL http://projects.example.net/example/bugnetwebservice.asmx/MobileBuildAction
,正如我與郵差與json的參數進行了測試:Groovy HttpBuilder json輸入問題
{
featureIdStr: 31,
actionStr: 1,
comment: "Hello world"
}
,並獲得響應:
{
"d": "Succeeded"
}
每當我嘗試運行它在Groovy中,但是,我得到這樣的迴應:
Jun 10, 2016 9:54:25 AM net.sf.json.JSONObject _fromBean
INFO: Property 'value' of class org.codehaus.groovy.runtime.GStringImpl has no read method. SKIPPED
Failure: 500
這裏是我的代碼:
@Grab(group='org.codehaus.groovy.modules.http-builder', module='http-builder', version='0.7.1')
import groovyx.net.http.*
import static groovyx.net.http.ContentType.*
import static groovyx.net.http.Method.*
def http = new HTTPBuilder("http://projects.example.net/")
def issueId = 31
def msg = "Build Failed"
def jsonBody = [:]
jsonBody.put("featureIdStr", issueId)
jsonBody.put("actionStr", 0)
jsonBody.put("comment", "${msg}: <a href='http://www.google.com'}'>Googles Job</a>")
http.request(POST, JSON) {
uri.path = "/example/bugnetwebservice.asmx/MobileBuildAction"
body = jsonBody
response.success = { resp ->
println "Success! ${resp.status}"
}
response.failure = { resp ->
println "Failure: ${resp.status}"
}
}
請幫忙!
你可以嘗試改變最後的'put'值' 「$ {}味精:Googles Job」 的ToString()'?我想我在HTTPBuilder中遇到了與String和GString處理有關的類似問題。 – bdkosher