
在下面的代码段中,paramstopost = [name:’John’,年龄:22]
@Grab(group='org.codehaus.groovy.modules.http-builder',module='http-builder',version='0.5.0')Boolean dohttpPost(String url,Map paramstopost,String fileContent) { httpBuilder http = new httpBuilder(url) def resp = http.request(Method.POST ) { req -> multipartentity mpe = new multipartentity() mpe.addPart "foo",new StringBody(fileContent) req.entity = mpe // body = paramstopost // no such property } println "response: ${resp}" return true} 有人有工作样品吗?
解决方法 刚刚让我的代码与旧的commons-httpclIEnt-3.1.jar一起工作(new httpBuilder(url)).request(Method.POST) { request ->multipartentity mpe = new multipartentity(httpMultipartMode.broWSER_COMPATIBLE);mpe.addPart('fileinput',new StringBody(params.fileinput))if (params.fileinput=='file') mpe.addPart('file1',new inputStreamBody(uploadedfile.inputStream,uploadedfile.ContentType,uploadedfile.originalfilename))else if (params.fileinput=='text') mpe.addPart('fileText',new StringBody(params.fileText))mpe.addPart('Tags1',new StringBody(params.Tags1)) request.entity = mperequest.getParams().setParameter("http.connection.timeout",http_TIMEOUT)request.getParams().setParameter("http.socket.timeout",http_TIMEOUT)response.success = { resp,reader -> render(text : "Successfully uploaded file\n\n${reader.text}")}response.failure = { resp -> render (status: 500,text: "http Failure Accessing Upload Service ${resp.statusline}" )} 希望这可以帮助
总结以上是内存溢出为你收集整理的Groovy中的HTTPBuilder和MultipartEntity / multipart表单数据全部内容,希望文章能够帮你解决Groovy中的HTTPBuilder和MultipartEntity / multipart表单数据所遇到的程序开发问题。
如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。
欢迎分享,转载请注明来源:内存溢出
微信扫一扫
支付宝扫一扫
评论列表(0条)