2016-07-15 261 views
0

对于我正在使用Rails的项目,我正在使用AlchemyData新闻API。我正在试图在pry中运行HTTP请求,如下所示(我用替换my_api_key替换了我自己的API密钥,为了清楚起见,>指示我输入的内容和=>返回给我的内容):HTTP请求:400错误

> uri = URI.parse("https://gateway-a.watsonplatform.net/calls/data/GetNews?apikey=MY_API_KEY&outputMode=json&start=now-24h&end=now&q.enriched.url.title=A[Kim^Kardashian]&q.enriched.url.docSentiment.type=positive") 
=> #<URI::HTTPS https://gateway-a.watsonplatform.net/calls/data/GetNews?apikey=MY_API_KEY&outputMode=json&start=now-24h&end=now&q.enriched.url.title=A[Kim^Kardashian]&q.enriched.url.docSentiment.type=positive> 

> http = Net::HTTP.new(uri.host, uri.port) 
=> #<Net::HTTP gateway-a.watsonplatform.net:443 open=false> 

> response = http.request(Net::HTTP::Get.new(uri.request_uri)) 
=> #<Net::HTTPBadRequest 400 Bad Request readbody=true> 

我不明白为什么我不断收到“400错误请求”错误。根据我的理解,这是(通常)在url出现错误时返回的,但是当我运行它时,它完美地起作用。我的语法有什么问题吗?还是有其他错误?如果是这样,那是什么?我怎样才能解决这个问题?

回答