HTTP Error 415 Unsupported media type

2019-08-29 07:22发布

问题:

I am still on the same problem as: Upload binary data with HTTP PUT with jersey jaxrs-ri-2.01

But I am one step further. Now I am testing my data upload with this tool: I'm Only Resting

The problem, and I don't know if it's a client or a server problem is that when I'm testing, I get HTTP 415 - Unsupported Media Type

In the client:

  • I have checked the PUT method
  • In the body I have put one blank line (return) and in the second line i wrote test

In the server, It was working until I added this parameter

 @FormDataParam("file") InputStream pBodyDataStream

and this code:

    try {
        OutputStream lOutputStream = new FileOutputStream(new File("F:/test.bin"));

        int read = 0;

        byte[] bytes = new byte[fragmentSize];

        while ((read = pBodyDataStream.read(bytes)) != -1) {
            lOutputStream.write(bytes, 0, read);
        }

        lOutputStream.close();
        pBodyDataStream.close();
    } catch (IOException e) {
        // fragment reception error

        // HTTP 500 error
        lOutput = xmlError("Upload error while transferring fragment");
        e.printStackTrace();
        return Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity(lOutput).build();
    }

Here is a screenshot of the test tool with the parameters:

Here is the cURL investigation:

The command line:

curl -v -H "application/octet-stream" -K params_curl.txt

The cURL parameters file:

url = "localhost:8080/ServeurWS/softplus/biens/arts/2345412/images?user=wow&pass=wow&taille=100&numfrag=1&taillefrag=10&md5=d6aa97d33d459ea3670056e737c99a3d&md6=5da8aa7126701c9840f99f8e9fa54976"
request="PUT"
upload-file="f:/vcredist.bmp"
output = "output.html"
user-agent = "superagent/1.0"

The headers I see, thanks to the -v option:

C:\Users\Dev\Desktop>curl -v -I -H "application/octet-stream" -K params_curl.txt
  % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current
                                 Dload  Upload   Total   Spent    Left  Speed
  0     0    0     0    0     0      0      0 --:--:-- --:--:-- --:--:--     0*   Trying ::1...
* Connected to localhost (::1) port 8080 (#0)
> PUT /ServeurWS/softplus/biens/arts/2345412/images?user=wow&pass=wow&taille=100&numfrag=1&taillefrag=10&md5=d6aa97d33d459ea3670056e737c99a3d&md6=5da8aa7126701
c9840f99f8e9fa54976 HTTP/1.1
> Host: localhost:8080
> User-Agent: superagent/1.0
> Accept: */*
> Content-Length: 5686
> Expect: 100-continue
>
< HTTP/1.1 100 Continue
} [5686 bytes data]
* We are completely uploaded and fine
< HTTP/1.1 415 Type de Support Non Supporté
< Server: Apache-Coyote/1.1
< Content-Type: text/html;charset=utf-8
< Content-Length: 1108
< Date: Wed, 02 Dec 2015 13:56:07 GMT
<
{ [1108 bytes data]
100  6794  100  1108  100  5686  11080  56860 --:--:-- --:--:-- --:--:-- 63177
* Connection #0 to host localhost left intact

The output.html file:

HTTP/1.1 100 Continue

HTTP/1.1 415 Type de Support Non Supporté
Server: Apache-Coyote/1.1
Content-Type: text/html;charset=utf-8
Content-Length: 1108
Date: Wed, 02 Dec 2015 13:56:07 GMT

<html><head><title>Apache Tomcat/6.0.44 - Rapport d'erreur</title><style><!--H1 {font-family:Tahoma,Arial,sans-serif;color:white;background-color:#525D76;font-size:22px;} H2 {font-family:Tahoma,Arial,sans-serif;color:white;background-color:#525D76;font-size:16px;} H3 {font-family:Tahoma,Arial,sans-serif;color:white;background-color:#525D76;font-size:14px;} BODY {font-family:Tahoma,Arial,sans-serif;color:black;background-color:white;} B {font-family:Tahoma,Arial,sans-serif;color:white;background-color:#525D76;} P {font-family:Tahoma,Arial,sans-serif;background:white;color:black;font-size:12px;}A {color : black;}A.name {color : black;}HR {color : #525D76;}--></style> </head><body><h1>Etat HTTP 415 - Unsupported Media Type</h1><HR size="1" noshade="noshade"><p><b>type</b> Rapport d'état</p><p><b>message</b> <u>Unsupported Media Type</u></p><p><b>description</b> <u>Le serveur a refusé cette requête car l'entité de requête est dans un format non supporté par la ressource demandée avec la méthode spécifiée.</u></p><HR size="1" noshade="noshade"><h3>Apache Tomcat/6.0.44</h3></body></html>

And there is no error in the Eclipse console...