【问题标题】:Possible URL encoding issues可能的 URL 编码问题
【发布时间】:2016-04-02 19:35:49
【问题描述】:

当我通过 Web 浏览器发出请求时,我有两个 HTTP 请求会产生相同的 CSV 输出。我省略了两个请求的 URL 参数的第一部分,因为它们是相同的。它只会更改您在下面看到的最后一个参数:

请求 A:

https://csv.business.tomtom.com/extern?...[other parameters]...&range_pattern=d-1

请求 B:

https://csv.business.tomtom.com/extern?...[other parameters]...&rangefrom_string=01/04/2016 00:00:01&rangeto_string=01/04/2016 23:59:59

CSV 输出

"start_time","end_time","distance","triptime","operatingtime","standstill","tours","fuel_usage"
"01/04/2016 09:27:39","01/04/2016 17:25:51","293121","15187","28692","2759","4","21.024"

但是,当我通过 rails 应用程序发出请求时,请求 B 出现错误。请求 A 正常。

错误:

CSV::MalformedCSVError
...
Illegal quoting in line 1.
...
@tripsSummary = CSV.parse(summaryResponse.to_s)

这些是 HTTP 响应:

响应 A

#<HTTP::Response/1.1 200 OK {"Access-Control-Allow-Origin"=>"*", "Access-Control-Allow-Methods"=>"GET", "Access-Control-Max-Age"=>"3600", "Access-Control-Allow-Headers"=>"Origin, X-Requested-With, Content-Type, Accept", "Content-Type"=>"text/comma-separated-values;charset=UTF-8", "Date"=>"Sat, 02 Apr 2016 19:16:04 GMT", "Connection"=>"close", "Transfer-Encoding"=>"chunked"}>

反应乙

#<HTTP::Response/1.1 200 OK {"Connection"=>"close", "Cache-Control"=>"no-cache", "Content-Type"=>"text/html; charset=iso-8859-1", "Pragma"=>"no-cache", "Content-Length"=>"108"}>

问题

  1. 请求 B 是否格式错误?
  2. 为什么它可以在浏览器中运行 不能在应用程序中工作?
  3. 参数 rangefrom_string=01/04/2016 00:00:01 是否存在编码问题?

【问题讨论】:

    标签: http ruby-on-rails-4 url-encoding


    【解决方案1】:

    您可能应该在range_fromrange_to 参数中将空格转义为%20。我不知道如何在 Ruby 中做到这一点,但 this question 看起来是一个好的开始。

    浏览器可能会自动转义 URL,这就是您在那里得到正确答案的原因。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2021-01-17
      • 2016-08-14
      • 2014-04-02
      • 2011-10-14
      • 2010-11-14
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多