我使用其他人编写的代码,偶尔我会有些困惑,在这些时候Stack Overflow会让我感到困惑.拜托,再次救我.
我们的网站允许人们上传图片,然后将其嵌入我们网站的文本中,如下所示:
<img src="http://site.com/image_script.php?p=some_image_identifier"/>
Run Code Online (Sandbox Code Playgroud)
我的问题是:
如果服务器返回"500"或"404",标识符"p"不会将我们引向图像?
我本以为它应该是"404",但那不是现在发生的事情.
是否可以在JavaScript中收集HTTP标头?在使用Firebug几天后,这只是我的想法.在我发现的其中一篇文章中,在JavaScript中找不到HTTP头是不可能的,而在firebug中,我们可以看到响应头(客户端)
所以我的问题是我们可以在JavaScript中缓存HTTP标头吗?
conn = httplib.HTTPConnection('thesite')
conn.request("GET","myurl")
conn.putheader('Connection','Keep-Alive')
#conn.putheader('User-Agent','Mozilla/5.0(Windows; u; windows NT 6.1;en-US) AppleWebKit/533.4 (KHTML, like Gecko) Chrome//5.0.375.126 Safari//5.33.4')
#conn.putheader('Accept-Encoding','gzip,deflate,sdch')
#conn.putheader('Accept-Language','en-US,en;q=0.8')
#conn.putheader('Accept-Charset','ISO-8859-1,utf-8;1=0.7,*;q=0.3')
conn.endheaders()
r1= conn.getresponse()
Run Code Online (Sandbox Code Playgroud)
它引发了一个错误:
conn.putheader('Connection','Keep-Alive')
File "D:\Program Files\python\lib\httplib.py", line 891, in putheader
raise CannotSendHeader()
Run Code Online (Sandbox Code Playgroud)
如果我注释掉putheader和endheaders,它运行良好.但我需要它保持活力.
有谁知道我做错了什么?
我正在Delphi中编写win32服务(应该能够翻译任何其他代码,如果你不懂delphi),需要获取网站的状态.我知道如何在.NET中执行此操作,但我不确定正常的基于Windows的编程.因此,我需要查询网站并返回状态代码200,301等.我的计划是解析返回的数据,如果我的某个网站发生故障,请发送电子邮件.
有人能伸出援助之手吗?
编辑:这是我最后使用的代码 - 使用TIDHttp Indy组件.
IdHTTP.Get('http://www.example.com');
if IdHTTP.Connected then begin
ResponseCode := IntToStr(IdHTTP.ResponseCode);
ShowMessage(ResponseCode);
end;
Run Code Online (Sandbox Code Playgroud) delphi service windows-services http-status-codes http-headers
我有一个发布HTTP重定向的页面.我需要将当前会话ID(jsessionid)附加到HTTP重定向的末尾,以将此id作为重定向中的GET参数传递.
可以mod_header通过Header append指令获取cookie值SetEnvIf吗?
是否应该重写?但mod_rewrite只是重写请求而不是响应,是吗?
如何在不触及后端代码的情况下从Apache角度解决这个问题?
更新:Apache-JVM由mod_jk或通过IBM HTTP Server连接到WebSphere处理.
我正在实施浏览器缓存,并遵循Google PageSpeed关于将Last-Modified设置为"过去足够远"的数据的建议.我的.htaccess中有以下内容:
<IfModule mod_headers.c>
<FilesMatch "\.(json|pdf|swf|bmp|gif|jpeg|jpg|png|svg|tiff|ico|flv|js)$">
Header Set Last-Modified "Fri, 01 Jan 2010 12:00:00 GMT"
</FilesMatch>
</IfModule>
Run Code Online (Sandbox Code Playgroud)
我的服务器上安装了mod_headers.
不幸的是,Google PageSpeed仍抱怨并警告我:
Leverage browser caching
The following cacheable resources have a short freshness lifetime. Specify an expiration at least one week in the future for the following resources:
Run Code Online (Sandbox Code Playgroud)
然后列出PNG,GIF,JPG等.雅虎YSlow说的基本相同.
查看我应该缓存的一个资源的响应头,我看到了:
Date: Tue, 19 Oct 2010 20:12:04 GMT
Server: Apache/2.2.14 (Ubuntu)
Last-Modified: Tue, 07 Sep 2010 23:51:33 GMT
Etag: "2e0e34-2a43-48fb413a96a20"
Accept-Ranges: bytes
Content-Length: 10819
Content-Type: image/png
Run Code Online (Sandbox Code Playgroud)
如您所见,Last-Modified数据与我在.htaccess中指定的数据不匹配.
我有什么想法我做错了吗?
有没有办法通过嗅探NTLM标头来计算出用户的名字?
我有一个应用程序访问NTLM auth'd站点,因此会打开一个Auth提示符,以便用户通过输入用户名/密码对站点进行身份验证.
有没有办法,只需访问标题,找出输入的用户名是什么?
它甚至可能吗?
谢谢,
Jonsie
我的PHP脚本有$ _SERVER ['HTTP_HOST']等于与我的服务器的ip无关的ip.
有人得到了一个简单的解释?
(我在想一些机器人发送一个完全错误的主机头,但我认为它不能连接到主机头错误的服务器= /)
谢谢
我发现如果我尝试PHP POST curl,postvars就会被发送.一旦我添加了内容类型的httpheader:application/jsonpostvars不会再发生了.我已经将postvars作为JSON字符串和查询字符串进行了尝试.
显示一些代码:
$ch = curl_init();
$post = json_encode(array('p1' => 'blahblahblah', 'p2' => json_encode(array(4,5,6))));
$arr = array();
array_push($arr, 'Content-Type: application/json; charset=utf-8');
curl_setopt($ch, CURLOPT_HTTPHEADER, $arr);
curl_setopt($ch, CURLOPT_URL, 'https://example.com/file.php');
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_POSTFIELDS, $post);
curl_exec($ch);
curl_close($ch);
Run Code Online (Sandbox Code Playgroud) 我正在玩一些API,我试图解决这个问题.
我正在通过API向我的服务器发出基本的HTTP身份验证请求.作为此请求的一部分,经过身份验证的密钥将作为用户名存储在HTTP标头中.
所以我的问题是,如何获取传入请求的内容,以便我可以对其进行检查?
我想做什么:
if incoming request has header == 'myheader':
do some stuff
else:
return ('not authorised')
Run Code Online (Sandbox Code Playgroud)
对于那些感兴趣的人,我试图让这个工作.
更新 我正在使用Django
http-headers ×10
apache ×3
http ×3
php ×2
python ×2
.htaccess ×1
curl ×1
delphi ×1
django ×1
firebug ×1
header ×1
httpd.conf ×1
httplib ×1
httprequest ×1
javascript ×1
json ×1
ntlm ×1
service ×1