首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >curl,play & expect 100继续标题

curl,play & expect 100继续标题
EN

Stack Overflow用户
提问于 2014-06-16 10:12:08
回答 1查看 3.1K关注 0票数 0

考虑一个在play中编写的web服务,除了POST请求(用于上传)。现在,在用中等尺寸图像(~75K)进行测试时,我发现了一种奇怪的行为。好吧,代码比长篇解释更清晰,所以:

代码语言:javascript
复制
$ curl -vX POST localhost:9000/path/to/upload/API -H "Content-Type: image/jpeg" -d @/path/to/mascot.jpg
* Hostname was NOT found in DNS cache
*   Trying 127.0.0.1...
* Connected to localhost (127.0.0.1) port 9000 (#0)
> POST /path/to/upload/API HTTP/1.1
> User-Agent: curl/7.35.0
> Host: localhost:9000
> Accept: */*
> Content-Type: image/jpeg
> Content-Length: 27442
> Expect: 100-continue
> 
< HTTP/1.1 100 Continue
< HTTP/1.1 200 OK
< Content-Type: application/json; charset=utf-8
< Content-Length: 16
< 
* Connection #0 to host localhost left intact
{"success":true}

正如您所看到的,curl决定添加标题Content-Length: 27442,但这不是真的,实际大小是75211,在游戏中,我确实有一个大小只有27442的身体。粗野的,这不是故意的行为。因此,我尝试了另一个工具,而不是curl,而是使用libwww-perl中的POST工具。

代码语言:javascript
复制
cat /path/to/mascot.jpg | POST -uUsSeE -c image/jpeg http://localhost:9000/path/to/upload/API
POST http://localhost:9000/path/to/upload/API
User-Agent: lwp-request/6.03 libwww-perl/6.05
Content-Length: 75211
Content-Type: image/jpeg

200 OK
Content-Length: 16
Content-Type: application/json; charset=utf-8
Client-Date: Mon, 16 Jun 2014 09:21:00 GMT
Client-Peer: 127.0.0.1:9000
Client-Response-Num: 1

{"success":true}

这一请求获得成功。因此,我开始更加关注工具之间的差异。对于初学者:Content-Length头是正确的,但是在第二次尝试中缺少了Expect头。无论哪种方式,我都希望请求成功。因此,在play中看到的标题的完整列表(通过request.headers)是:

卷发:

代码语言:javascript
复制
ArrayBuffer((Content-Length,ArrayBuffer(27442)), 
            (Accept,ArrayBuffer(*/*)),
            (Content-Type,ArrayBuffer(image/jpeg)), 
            (Expect,ArrayBuffer(100-continue)), 
            (User-Agent,ArrayBuffer(curl/7.35.0)), 
            (Host,ArrayBuffer(localhost:9000)))

对于libwww-perl帖子:

代码语言:javascript
复制
ArrayBuffer((TE,ArrayBuffer(deflate,gzip;q=0.3)), 
            (Connection,ArrayBuffer(TE, close)), 
            (Content-Length,ArrayBuffer(75211)), 
            (Content-Type,ArrayBuffer(image/jpeg)), 
            (User-Agent,ArrayBuffer(lwp-request/6.03 libwww-perl/6.05)),
            (Host,ArrayBuffer(localhost:9000)))

因此,我当前的想法是:更简单的perl工具使用了一个请求,这是错误的做法。更好的方法是等待100 continue确认(特别是如果您要上传几GB的数据.)。curl将继续发送数据,直到收到200 OK或一些错误的请求错误代码。那么,为什么play不等待下一个块就发送200 OK响应呢?是因为curl指定了错误的Content-Length吗?如果是错的话..。(这可能是指当前块的大小?)。那么问题在哪里呢?在卷曲里还是在网络游戏里?我该怎么解决呢?

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2014-06-17 11:04:10

问题出在我的卷发命令上。当我应该使用-d参数时,我使用了--data--data-ascii的缩写--data-binary参数。

票数 3
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/24241294

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档