0

我仍然遇到同样的问题: Upload binary data with HTTP PUT with jersey jaxrs-ri-2.01

但我更进一步。现在我正在使用这个工具测试我的数据上传: 我只是在休息

问题,我不知道是客户端问题还是服务器问题,当我测试时,我得到HTTP 415 - Unsupported Media Type

在客户端:

  • 我已经检查了PUT方法
  • 在正文中我放了一个空行(返回),在第二行中我写了测试

在服务器中,它一直在工作,直到我添加了这个参数

 @FormDataParam("file") InputStream pBodyDataStream

这个代码:

    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();
    }

这是带有参数的测试工具的屏幕截图:

截图 1

这是卷曲调查:

命令行:

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

cURL 参数文件:

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"

由于-v选项,我看到的标题:

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

output.html文件:

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>

而且 Eclipse 控制台中没有错误...

4

0 回答 0