写适当的“HEAD”和“GET”请求在winsock c ++ [英] writing proper "HEAD" and "GET" request in winsock c++

查看:179
本文介绍了写适当的“HEAD”和“GET”请求在winsock c ++的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

实际上,我正在编码使用winsock c + +下载文件,并获得我的HEAD标题。



这是我真正的)

 
HEAD /files/ODBC%20Programming%20in%20C%2B%2B.pdf HTTP / 1.0
主机: devmentor-unittest.googlecode.com

回应是:

 
HTTP / 1.0 404未找到
Content-Type:text / html; CHARset = UTF-8
Set-Cookie:PREF = ID = feeed8106df5e5f1:TM = 1370157208:LM = 1370157208:S = 10bN4nrXqkcCDN5n; expires = Tue,02-Jun-2015 07:13:28 GMT; path = /; domain = devmentor-unittest.googlecode.com
X-Content-Type-Options:nosniff
日期:Sun,02 Jun 2013 07:13:28 GMT
服务器:codesite_downloads
Content-Length:974
X-XSS-Protection:1; mode = block
X-Frame-Options:SAMEORIGIN

但是如果我这样做:

 
GET /files/ODBC%20Programming%20in%20C%2B%2B.pdf HTTP / 1.0
主机:devmentor-unittest.googlecode.com



文件成功下载....



我触发HEAD请求...它也带来了以下

 
HTTP / 1.0 200 OK
Content-Length:320381
Content-Type:application / pdf
Content-Disposition:attachment; filename =ODBC Programming in C ++。pdf
接受范围:bytes
日期:Sun,02 Jun 2013 05:47:11 GMT
最后修改:Sun,2007年11月11日03 :17:59 GMT
到期日:Sun,09 Jun 2013 05:47:11 GMT
缓存控制:public,max-age = 604800
服务器:DFE / largefile
//这样的东西.....

问题:为什么HEAD首先返回假的error not found该文件被下载使用GET,下载后HEAD也会返回好东西我需要...哪里有我错了..



我试图的文件这里下载的是 http:// devmentor-unittest .googlecode.com / files / ODBC%20Programming%20in%20C%2B%2B.pdf (例如)

解决方案

问题不在你的结尾。 Google代码根本没有正确实现HEAD。这是 5年前报告的,仍然是一个未决问题:



问题660:为文件下载网址支持HTTP HEAD方法


Actually I was coding for downloading the files in HTTP using winsock c++ and to get the details I fired "HEAD" header..

(this is what actually I did)

HEAD /files/ODBC%20Programming%20in%20C%2B%2B.pdf HTTP/1.0
Host: devmentor-unittest.googlecode.com

Response was:

HTTP/1.0 404 Not Found
Content-Type: text/html; charset=UTF-8
Set-Cookie: PREF=ID=feeed8106df5e5f1:TM=1370157208:LM=1370157208:S=10bN4nrXqkcCDN5n; expires=Tue, 02-Jun-2015 07:13:28 GMT; path=/; domain=devmentor-unittest.googlecode.com
X-Content-Type-Options: nosniff
Date: Sun, 02 Jun 2013 07:13:28 GMT
Server: codesite_downloads
Content-Length: 974
X-XSS-Protection: 1; mode=block
X-Frame-Options: SAMEORIGIN

But if I do:

GET /files/ODBC%20Programming%20in%20C%2B%2B.pdf HTTP/1.0
Host: devmentor-unittest.googlecode.com

The file sucessfully gets downloaded....

After then after I download, again if I fire the HEAD request... it also brings up the following

HTTP/1.0 200 OK
Content-Length: 320381
Content-Type: application/pdf
Content-Disposition: attachment; filename="ODBC Programming in C++.pdf"
Accept-Ranges: bytes
Date: Sun, 02 Jun 2013 05:47:11 GMT
Last-Modified: Sun, 11 Nov 2007 03:17:59 GMT
Expires: Sun, 09 Jun 2013 05:47:11 GMT
Cache-Control: public, max-age=604800
Server: DFE/largefile
//something like this.....

Question: why "HEAD" is returning the false "error not found" at first but the file gets downloaded in using "GET" and after downloading "HEAD" also returns goodies i need...where have i mistaken..

The file I am trying to download here is "http://devmentor-unittest.googlecode.com/files/ODBC%20Programming%20in%20C%2B%2B.pdf" (just for example)

解决方案

The problem is not on your end. Google Code simply does not implement HEAD correctly. This was reported 5 years ago and is still an open issue:

Issue 660: support HTTP HEAD method for file download urls

这篇关于写适当的“HEAD”和“GET”请求在winsock c ++的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆