当我通过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 app发出请求时,我收到了请求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"}>
回应B
#<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"}>
问题
答案 0 :(得分:1)
您可能应该在%20
和range_from
参数中以range_to
转义空格。我不知道如何在Ruby中做到这一点,但this question看起来是一个好的开始。
浏览器可能会自动转义URL,这就是您在那里得到正确答案的原因。