Posting a File and Associated Data to a RESTful WebService preferably as JSON

后端 未结 11 841
没有蜡笔的小新
没有蜡笔的小新 2020-11-22 10:45

This is probably going to be a stupid question but I\'m having one of those nights. In an application I am developing RESTful API and we want the client to send data as JSON

11条回答
  •  感情败类
    2020-11-22 11:14

    Please ensure that you have following import. Ofcourse other standard imports

    import org.springframework.core.io.FileSystemResource
    
    
        void uploadzipFiles(String token) {
    
            RestBuilder rest = new RestBuilder(connectTimeout:10000, readTimeout:20000)
    
            def zipFile = new File("testdata.zip")
            def Id = "001G00000"
            MultiValueMap form = new LinkedMultiValueMap()
            form.add("id", id)
            form.add('file',new FileSystemResource(zipFile))
            def urld ='''http://URL''';
            def resp = rest.post(urld) {
                header('X-Auth-Token', clientSecret)
                contentType "multipart/form-data"
                body(form)
            }
            println "resp::"+resp
            println "resp::"+resp.text
            println "resp::"+resp.headers
            println "resp::"+resp.body
            println "resp::"+resp.status
        }
    

提交回复
热议问题