【问题标题】:CasperJS Request to Squid Proxy Generating HTTP Response 400 on ajax POSTCasperJS 请求 Squid 代理在 ajax POST 上生成 HTTP 响应 400
【发布时间】:2018-01-13 21:18:02
【问题描述】:

我想知道是否有人对我在通过 casperJS 发送 POST 请求时几乎一直遇到的以下错误有任何经验。

this.open('https://'+host+'/test.php?test=new1', {
    method: 'post',
    data:   {
        'host':hostID,    
        'func':'newjob',
        'apikey': key,
        'test':testing
    }
})

带有以下推理的错误 400 非常神秘,并且没有参考 Squid 文档中的错误。

1515876312.758 0 10.2.1.101 NONE/400 4272 CONNECT 错误:双 CR - NONE/- text/html 1515876312.775 0 10.2.1.101 无/400 4270 连接错误:双 CR-无/-文本/html 1515876312.811 0 10.2.1.101 无/400 4272 连接错误:双 CR-无/-文本/html 1515876312.814 0 10.2.1.101 无/400 4270 连接错误:双 CR-无/-文本/html 1515876312.852 0 10.2.1.101 无/400 4272 连接错误:双 CR-无/-文本/html 1515876312.967 0 10.2.1.101 NONE/400 4235 CONNECT 错误:双 CR - NONE/- text/html 1515876314.258 0 10.2.1.101 NONE/400 4296 CONNECT 错误:双 CR - NONE/- text/html 1515876314.329 0 10.2.1.101 无/400 4296 连接错误:双 CR-无/-文本/html 1515876314.368 0 10.2.1.101 NONE/400 4296 CONNECT 错误:双 CR - NONE/- text/html 1515876314.672 0 10.2.1.101 无/400 4351 连接错误:双 CR-无/-文本/html 1515876314.738 0 10.2.1.101 NONE/400 4351 CONNECT 错误:双 CR - NONE/- text/html 1515876314.773 0 10.2.1.101 无/400 4281 连接错误:双 CR-无/-文本/html 1515876314.777 0 10.2.1.101 NONE/400 4351 CONNECT 错误:双 CR - NONE/- text/html 1515876314.829 0 10.2.1.101 NONE/400 4281 CONNECT 错误:双 CR - NONE/- text/html

CasperJS 发出的输出是:

 [info] [phantom] Starting...
 [info] [phantom] Running suite: 1 step
 Using UA=Mozilla/5.0 (Macintosh; U; Intel Mac OS X 10_6_8; de-at) AppleWebKit/533.21.1 (KHTML, like Gecko) Version/5.0.5 Safari/533.21.1
 [info] [phantom] Step anonymous 1/1: done in 52ms.
 [info] [phantom] Step anonymous 2/3: done in 67ms.
 [warning] [phantom] Loading resource failed with status=fail: https://10.2.1.199/test.php?test=new1

我查看了这个 SO Q/A:he following HTTP request returns a 400 ERR_INVALID_REQ -

这似乎是相似的,但如果它们在问题中存在联系 - 有没有人知道如何让 CasperJS/phantomJS 不添加空格?

【问题讨论】:

  • 我不熟悉 squid 代理,但是您确定您在请求中提供了所有必需的标头吗?

标签: post casperjs squid http-status-code-400


【解决方案1】:

问题是以下几种情况的结合:

Casper/Phantom 显然在请求中有两个回车符,Squid 3.1 不喜欢这样。

在 squid.conf 设置中:

relaxed_header_parser 开启

这并不能在 centos 6.x 上解决 Squid 3.1.x 中的问题,但如果您升级到 squid 3.4,它可以解决问题。

【讨论】:

  • 作为后续 - 这是由于我用来选择 UA 字符串的输入文件上的 windows 样式 crlf。改成 unix syle LF 只能彻底解决问题。
猜你喜欢
  • 2017-09-25
  • 1970-01-01
  • 2020-11-17
  • 1970-01-01
  • 1970-01-01
  • 2021-07-10
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多