【发布时间】: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"}>
问题
- 请求 B 是否格式错误?
- 为什么它可以在浏览器中运行 不能在应用程序中工作?
- 参数 rangefrom_string=01/04/2016 00:00:01 是否存在编码问题?
【问题讨论】:
标签: http ruby-on-rails-4 url-encoding