用于文件上载的curl命令行帮助

时间:2014-07-03 05:07:44

标签: curl jersey

我有一个基于Jersey的REST API,它的签名看起来像这样

@POST
    @Path("{businessId}/logo/add/")
    @Consumes(MediaType.MULTIPART_FORM_DATA)
    @Produces(MediaType.TEXT_PLAIN)
    public Response uploadLogo(
        @PathParam("businessId") String businessId,
        FormDataMultiPart form
    ) {
......

我尝试了几个curl命令行,以尝试使用REST api上传图像文件。但我似乎无法使它工作。我得到415.我理解415错误代码,但我无法弄清楚发生了什么。我的请求中的Content-Type是正确的(multipart / form-data)

  

curl -i -X POST -F" imageFile =。/ image.jpg"   http://myserver.com:8080/admin/02D0828864100000000B28C545B728F4/icon/add   -v

     

POST / admin / 02D0828864100000000B28C545B728F4 / icon / add HTTP / 1.1   User-Agent:curl / 7.30.0   主持人:myserver:8080   接受: /   内容长度:176   期待:100-继续   内容类型:multipart / form-data;边界= ---------------------------- c3081bfebd64

< HTTP/1.1 100 Continue
HTTP/1.1 100 Continue
< HTTP/1.1 415 Unsupported Media Type
HTTP/1.1 415 Unsupported Media Type
< Content-Length: 0
Content-Length: 0
* Server Jetty(9.1.z-SNAPSHOT) is not blacklisted
< Server: Jetty(9.1.z-SNAPSHOT)
Server: Jetty(9.1.z-SNAPSHOT)

* HTTP error before end of send, stop sending
< 
* Closing connection 0

1 个答案:

答案 0 :(得分:0)

您是否尝试过内容类型

curl -H“Content-Type:multipart / form-data”-i -X POST -F“imageFile =。/ image.jpg”http://myserver.com:8080/admin/02D0828864100000000B28C545B728F4/icon/add -v