- android - RelativeLayout 背景可绘制重叠内容
- android - 如何链接 cpufeatures lib 以获取 native android 库?
- java - OnItemClickListener 不起作用,但 OnLongItemClickListener 在自定义 ListView 中起作用
- java - Android 文件转字符串
所以我有一个程序可以使用裸套接字下载网页。我必须使用裸套接字,不能使用请求或 urllib 等任何东西。我在 Squid 代理后面的网络上,所以我的 python 程序只是 connect
到代理服务器并使GET 请求我从 HAR 文件中获取的对象。我使用 curl like 测试了请求
curl https://apis.google.com/_/scs/abc-static/_/js/k=gapi.gapi.en.wgbKiK972Ko.O/m=gapi_iframes,googleapis_client,plusone/rt=j/sv=1/d=1/ed=1/rs=AItRSTOlX0YCaQmKijyj5lpKQ5AVm7UE6A/cb=gapi.loaded_0 -o out_file
然后我将输出作为正确的整个文件。我检查了响应的 header ,它们是
HTTP/1.1 200 OK
Vary: Accept-Encoding
Content-Type: text/javascript; charset=UTF-8
Last-Modified: Thu, 11 Dec 2014 20:44:59 GMT
Date: Fri, 12 Dec 2014 03:38:46 GMT
Expires: Sat, 12 Dec 2015 03:38:46 GMT
X-Content-Type-Options: nosniff
Server: sffe
X-XSS-Protection: 1; mode=block
Cache-Control: public, max-age=31536000
Age: 1065247
Alternate-Protocol: 443:quic,p=0.02
Transfer-Encoding: chunked
现在我尝试使用 python 中的套接字编程来做同样的事情:
HOST = 'proxy.address.of.squid.proxy'
PORT = 3128
s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
s.connect((HOST, PORT))
url = 'https://apis.google.com/_/scs/abc-static/_/js/k=gapi.gapi.en.wgbKiK972Ko.O/m=gapi_iframes,googleapis_client,plusone/rt=j/sv=1/d=1/ed=1/rs=AItRSTOlX0YCaQmKijyj5lpKQ5AVm7UE6A/cb=gapi.loaded_0'
httpVrsn = 'HTTP/1.1'
domain = 'apis.google.com'
objReq = 'GET '+url+' '+httpVrsn+'\r\nHost: '+domain+'\r\n\r\n';
s.send(objReq);
data = '';
try:
data = s.recv(1024);
print data
# other non-relevant stuff
我得到的输出是
HTTP/1.0 501 Not Implemented
Server: squid/3.1.19
Mime-Version: 1.0
Date: Wed, 24 Dec 2014 10:25:42 GMT
Content-Type: text/html
Content-Length: 3576
X-Squid-Error: ERR_UNSUP_REQ 0
Vary: Accept-Language
Content-Language: en
X-Cache: MISS from localhost
X-Cache-Lookup: NONE from localhost:3128
Via: 1.0 localhost (squid/3.1.19)
Connection: close
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
<html><head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<title>ERROR: The requested URL could not be retrieved</title>
<style type="text/css"><!--
/*
Stylesheet for Squid Error pages
Adapted from design by Free CSS Templates
http://www.freecsstemplates.org
Released for free under a Creative Commons Attribution 2.5 License
*/
/* Page basics */
* {
font-family: verdana, sans-serif;
}
html body {
margin: 0;
padding: 0;
background: #efefef;
font-size: 12px;
color: #1e1e1e;
}
所以我查看了this这解释了我的 Squid 代理 3.1 不支持 Transfer-Encoding: chunked 但它说 POST 请求就是这种情况,我不确定它是否也适用于 GET 请求。我还检查了Unable to test HTTP PUT-based file upload via Squid Proxy .我不明白 curl 甚至我的浏览器如何能够在同一代理后面的同一网络上请求时获取内容,但通过 python 我无法成功获取响应?
那么有什么方法可以让我的 python 程序在不调整 Squid 代理的情况下工作,因为我无法控制代理。
最佳答案
Curl 使用 CONNECT 方法,这是一种隧道方法。代理仅在 TCP 级别连接到远程端,curl 执行所有通信,包括 TLS 握手。所有 TCP/IP 数据包都由代理来回“铲除”。但请注意,在某些条件下(例如,当管理员/公司将他自己的 CA 证书放入您的证书池时),代理的静默拦截 (MITM) 是可能的。
您的 Python 脚本所做的是要求代理与远程端通信。不知何故,您的代理无法进行 TLS 连接(在构建期间未配置或禁用,或者根本无法进行其他操作)。
要配置 Squid,请参阅 http://wiki.squid-cache.org/Features/HTTPS
关于python - Squid 代理在 python 发出的 GET 请求上给出 501 但不 curl ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27636360/
我有一个发出值的 Observable 源 source1,如果它没有发出任何东西超过 2 秒,我想切换到后备源 source2。如果 source1 再次发射,我想从中发射。依此类推,无限期。 到目
我正在使用 postfix 发送电子邮件。当我将电子邮件发送到其他域时它工作正常,但是当我将电子邮件发送到配置后修复的同一个域时它不发送电子邮件。 下面是我的配置: myhostname = [FQD
我最近将 ipython 和 pandas 更新为最新的稳定版本。它导致 matplotlib 中出现了一些奇怪的行为,如果我从终端运行(以前的行为)脚本,我将无法显示数字。如果我在 ipython
我的应用程序是一个网络应用程序。它的工作是接收我想将它们作为信号发出的数据包流(QByteArray)。这样做会不会效率低下?我关心复制大缓冲区。 最佳答案 QByteArray 使用 Copy-on
有 QTableWidget。我需要发送带有行列和文本的 cellChanged 信号。我怎样才能做到这一点? —— 我已经用插槽连接了信号。我需要发送 信号。 最佳答案 您必须使用 connect
我编写了一个简单的玩具语言编译器前端,它使用 llvm-sys 生成 LLVM IR (LLVM 的 C library 的 Rust 绑定(bind))。然后我通过创建 LLVMTargetMach
我想知道如何像那里描述的那样发出 HTTP POST 请求 http://code.google.com/apis/documents/docs/3.0/developers_guide_protoc
简单的问题。我需要在 GWT 中发出一个重定向到新页面的 GET 请求,但我找不到正确的 API。 有吗?我应该自己简单地形成 URL 然后做 Window.Location.replace ? (原
我正在使用 paging3我有两个不同的寻呼源。问题是Coroutine Scope只发出第一个寻呼流 在 ViewModel我有两个分页流程 val pagingFlow1 = Pager(Pagi
docker doc 中没有任何解释,也没有 docker 中看似任何内置变量来查找构建图像的原始工作目录。 我想在不同的目录上运行命令,并在某个时候回到我启动 docker build 的位置。 我
我试图使一个puppeteer.js机器人能够暂停并恢复其工作。 总的来说,我有一个带有十几个异步方法的类,事件发射器和一个名为“state”的属性,该属性使用setter进行更改。当我发生事件“停止
这个问题已经有答案了: Is it possible to send custom headers with an XHR ("Ajax" request)? (1 个回答) 已关闭 4 年前。 我想
如果浏览器打开与远程服务器的连接,是否可以通过 Javascript 访问同一连接? 我的网络上有一个小型以太网模块,我的编程有点像这样(伪代码): private var socket while(
尝试发出 HTTP 请求时,出现错误: {-# LANGUAGE OverloadedStrings #-} import Network.HTTP.Conduit -- the main modul
我有这个异步任务: public class likeTheJoke extends AsyncTask{ @Override protected Void doInBa
当进程终止并为其发出 wait() 时会发生什么?当一个子进程终止但没有人为其执行 wait() 时会发生什么?如果对尚未终止的进程执行 wait() 会发生什么情况? 最佳答案 如果我误解了这些问题
我尝试使用以下小部件结构、信号连接和回调将与 GtkTextView 支持的击键相关的信号(CTRL+a、CTRL+x 等)附加到工具栏按钮: typedef struct { GtkWidg
我有以下 base64 编码的字符串,我需要使用 Swift 对它进行 base64 解码: KimHser2RvFf9RPjajWO4K/odT51hTlISwMKNIfPUC+gXYZKNjGDC
我正在使用 Facebook Messenger webview 显示表单,在提交时,我想将消息发送回用户并关闭 webview。我现在的问题是 webview/浏览器没有发送消息就关闭了。我不知道这
很难说出这里要问什么。这个问题模棱两可、含糊不清、不完整、过于宽泛或夸夸其谈,无法以目前的形式得到合理的回答。如需帮助澄清此问题以便重新打开,visit the help center . 关闭 1
我是一名优秀的程序员,十分优秀!