我仍然遇到同样的问题: Upload binary data with HTTP PUT with jersey jaxrs-ri-2.01
但我更进了一步。现在我用这个工具测试我的数据上传: I'm Only Resting
问题,我不知道客户端或服务器问题是否在我测试时,我得到 HTTP 415 - 不支持的媒体类型
在客户端:
在服务器中,它一直工作,直到我添加了这个参数
<!DOCTYPE html>
<html>
<head>
<style>
body {
margin: 0px;
background-color: green;
}
.container {
margin-top: 0px;
margin-bottom: 0px;
margin-left: 10%;
margin-right: 10%;
}
.head {
background-color: gray;
}
.nav {
background-color: blue;
}
.content {
background-color: lime;
}
</style>
</head>
<body>
<div class="container">
<div class="head">
<h1>Welcome to my page!</h1>
</div>
<div class="nav">
<h2>some text</h2>
</div>
<div class="content">
<p>Some text in content</p>
</div>
</div>
</body>
</html>
和这段代码:
@FormDataParam("file") InputStream pBodyDataStream
以下是带有参数的测试工具的屏幕截图:
以下是cURL调查:
命令行:
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();
}
cURL参数文件:
curl -v -H "application/octet-stream" -K params_curl.txt
我看到的标题,感谢 -v 选项:
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"
output.html 文件:
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
Eclipse控制台中没有错误......