我正在建立到IIS Web服务器的HTTP连接,并发送一个POST请求,其中包含使用Transfer-Encoding:chunked编码的数据.当我这样做时,IIS只是关闭连接,没有错误消息或状态代码.根据HTTP 1.1规范,
所有HTTP/1.1应用程序必须能够接收和解码"分块"传输编码
所以我不明白为什么它(a)不处理该编码和(b)它没有发回状态代码.如果我更改发送Content-Length而不是Transfer-Encoding的请求,则查询会成功,但这并不总是可行的.
当我对Apache尝试相同的事情时,我得到一个"需要411长度"的状态和一条消息"chunked Transfer-Encoding forbidden".
为什么这些服务器不支持此编码?
HTTP服务器通过多个数据包发送数据的正确方法是什么?
例如,我想传输一个文件,我发送的第一个数据包是:
HTTP/1.1 200 OK
Content-type: application/force-download
Content-Type: application/download
Content-Type: application/octet-stream
Content-Description: File Transfer
Content-disposition: attachment; filename=test.dat
Content-Transfer-Encoding: chunked
400
<first 1024 bytes here>
400
<next 1024 bytes here>
400
<next 1024 bytes here>
Run Code Online (Sandbox Code Playgroud)
现在我需要制作一个新包,如果我发送:
400
<next 1024 bytes here>
Run Code Online (Sandbox Code Playgroud)
所有的客户都关闭了我的连接,文件被缩短了.
我在第二个数据包中放入哪些标头继续使用数据流?
作为此问题的后续内容,是否可以为大型静态文件禁用"Transfer-Encoding:Chunked"方法,从而强制返回Content-Length?
我的网站提供了一些Flash文件.小的(500-700kb)报告Content-Length罚款,但是大的(大约3MB)不报告,而是使用chunked模式.
尽管文件下载正常,但Flash预加载器不起作用,因为它无法判断文件的长度,因此无法确定加载的百分比.
我是编写动态处理程序来提供静态文件的唯一选择吗?
谢谢.
我是否知道如何使用"Transfer-Encoding:chunked"处理/读取响应?
目前我正在使用common-httpclient.3.1
我目前的编码如下(只能处理标题中内容长度的响应): -
httppost = new PostMethod(localurl);
httppost.setRequestHeader("Content-Type", "application/xml; charset=utf-8");
RequestEntity entity = new StringRequestEntity(in, "application/xml", "UTF-8");
httppost.setRequestHeader("Content-length", entity.getContentLength()+"");
httppost.setRequestEntity(entity);
for (int i=0; i<retryAttempt; i++) {
try {
httpclient.executeMethod(httppost);
if (httppost.getStatusCode() == 200) {
br = new BufferedReader(new InputStreamReader(httppost.getResponseBodyAsStream(), httppost.getResponseCharSet()));
String reply = null;
long len = httppost.getResponseContentLength();
if(len != 0) {
char[] cbuf = new char[Integer.parseInt(len+"")];
if (br.read(cbuf, 0, Integer.parseInt(len+"")) != -1 ) {
repOut = String.valueOf(cbuf);
}
}else{
while ((reply = br.readLine()) != null) {
if (!reply.equals("")) …Run Code Online (Sandbox Code Playgroud) 我需要向Web服务器发送POST请求,并能够读取所述服务器发送的响应.我试着用这个代码使用HTTPBuilder lib:
def http = new HTTPBuilder('http://myServer/')
http.setProxy("Proxy_IP", 8080, "http")
postBody = [cmd:'e',format:'sep',c:'a',b:'b',t:'u',r:'r',kl:'lop']
http.post( body: postBody,
requestContentType: URLENC ){ resp ->
HttpEntity he = resp.getEntity()
println "${resp.getAllHeaders()}"
println he.getContentType()
println "${resp.getEntity().getContent()}"
}
Run Code Online (Sandbox Code Playgroud)
执行此代码时出现异常:
ERROR errors.GrailsExceptionResolver - EOFException occurred when processing request: [GET] /PROJECT/home/index
Unexpected end of ZLIB input stream. Stacktrace follows:
Message: Unexpected end of ZLIB input stream
Line | Method
->> 240 | fill in java.util.zip.InflaterInputStream
- - - - - - - - - - - - - …Run Code Online (Sandbox Code Playgroud) 我写了一个客户端应用程序,假设从Web服务器下载文件,非常简单:
using (WebClient webClient = new WebClient())
{
webClient.DownloadFile("http://localhost/audiotest/audio.wav",
@"C:\audio.wav");
}
Run Code Online (Sandbox Code Playgroud)
该网站(音频文件位于:http://localhost/audiotest/audio.wav)具有标题Transfer-Encoding:chunked
当我运行该程序时,我收到以下错误:
服务器提交了协议违规.Section = ResponseBody Detail =响应块格式无效
当服务器包含Transfer-Encoding:chunked header时,如何下载文件?
我使用Apache HttpClient来发布多个文件服务器.这是代码:
public static HttpResponse stringResponsePost(String urlString, String content, byte[] image,
HttpContext localContext, HttpClient httpclient) throws Exception {
URL url = new URL(URLDecoder.decode(urlString, "utf-8"));
URI u = url.toURI();
HttpPost post = new HttpPost();
post.setURI(u);
MultipartEntity reqEntity = new MultipartEntity();
StringBody sb = new StringBody(content, HTTP_CONTENT_TYPE_JSON, Charset.forName("UTF-8"));
ByteArrayBody ib = new ByteArrayBody(image, HTTP_CONTENT_TYPE_JPEG, "image");
reqEntity.addPart("interview_data", sb);
reqEntity.addPart("interview_image", ib);
post.setEntity(reqEntity);
HttpResponse response = null;
response = httpclient.execute(post, localContext);
return response;
}
Run Code Online (Sandbox Code Playgroud)
问题是,MultipartEntityclass只有isChunked()方法(总是返回false),如果我希望为我的multipart实体启用chucked编码,则没有"setChunked(boolean)"选项.
我的问题是:
HTTP multipart和chunking可以根据协议规范共存吗?如果不是,为什么像其他实体 …
我有一个问题handeling http chunked传输编码.
我正在使用:
django只能处理带有content-length头字段的reqular http请求,但是当处理TE(Transfer-Encoding),chunked或gzip时,它返回一个空结果.
我正在考虑两种方法:
任何人都可以提供上述2种选择中的任何一种(当然更受欢迎的选项)
谢谢!
在格雷厄姆的第一次调查之后,这是对我的问题的延伸:
首先,感谢您的快速反应.正在使用的客户是Axis,它是另一家公司与我们沟通的系统的一部分.我已经WSGIChunkedRequest On设置了,我也对我的wsgi包装做了一些修改,如下所示:
def application(environ, start_response):
if environ.get("mod_wsgi.input_chunked") == "1":
stream = environ["wsgi.input"]
print stream
print 'type: ', type(stream)
length = 0
for byte in stream:
length+=1
#print length
environ["CONTENT_LENGTH"] = len(stream.read(length))
django_application = get_wsgi_application()
return django_application(environ, start_response)
Run Code Online (Sandbox Code Playgroud)
但它给了我那些错误(从apache的error.log文件中提取):
[Sat Aug 25 17:26:07 2012] [error] <mod_wsgi.Input object at 0xb6c35390>
[Sat Aug 25 17:26:07 2012] [error] type: <type 'mod_wsgi.Input'>
[Sat Aug 25 17:26:08 …Run Code Online (Sandbox Code Playgroud) 我正在尝试将音频发送到希望将音频作为分块帖子的网络服务。发送预先录制的文件工作正常,但运行下面的代码不会像看起来那样向服务器发送任何内容。卷曲是否试图将所有内容都发送到一个块中?我找不到任何选项,例如要求它对每个 xxx 字节进行分块。
gst-launch-1.0 pulsesrc ! "audio/x-raw,rate=16000,channels=1,format=S16LE" ! fdsink sync=false | \
curl --header "Transfer-Encoding: chunked" --data-binary @- http://...
Run Code Online (Sandbox Code Playgroud) 我正在Rails版本4.1.7/Nginx上构建一个API,它响应来自iOS应用程序的请求.我们在客户端上看到了一些奇怪的缓存,我们认为它与Rails发送回的响应中的微小差异有关.我的问题......
1)我想理解为什么,对于完全相同的请求(只更改了Authorization标头值),Rails transfer-encoding: chunked有时Content-Length: <number>会发回?我认为它可能与响应大小有关,但在我下面粘贴了标题的示例响应中,正文中返回的数据完全相同.
2)有没有办法强迫它使用Content-Length?我们认为这将解决我们的iOS应用程序中的缓存问题.
回复#1
HTTP/1.1 200 OK
Cache-Control: max-age=0, private, must-revalidate
Content-Type: application/json; charset=utf-8
Date: Wed, 18 Mar 2015 00:59:31 GMT
ETag: "86f277ea63295460d4f3bed9a073eaa2"
Server: nginx/1.6.2
Status: 200 OK
X-Content-Type-Options: nosniff
X-Frame-Options: SAMEORIGIN
X-Request-Id: dd36f139-1986-4da6-9645-4438d41e74b0
X-Runtime: 0.123865
X-XSS-Protection: 1; mode=block
transfer-encoding: chunked
Connection: keep-alive
Run Code Online (Sandbox Code Playgroud)
请求#2
HTTP/1.1 200 OK
Cache-Control: max-age=0, private, must-revalidate
Content-Type: application/json; charset=utf-8
Date: Wed, 18 Mar 2015 00:59:36 GMT
ETag: "86f277ea63295460d4f3bed9a073eaa2"
Server: nginx/1.6.2
Status: 200 OK
X-Content-Type-Options: nosniff
X-Frame-Options: SAMEORIGIN …Run Code Online (Sandbox Code Playgroud)