Scala调度简单获取请求

编程入门 行业动态 更新时间:2024-10-27 01:29:10
本文介绍了Scala调度简单获取请求的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我正在尝试使用Scala Dispatch执行简单的GET请求,但是我出错了,出现404错误.意外的响应状态:404

I am trying to execute a Simple GET request with Scala Dispatch, however I am erroring out with a 404 error. Unexpected response status: 404

这是一个有效的示例:

www.google/finance/info?infotype=infoquoteall&q=tsla,goog

但是我是否知道我的错误在代码中的位置

But am I amunsure of where my error is in my code

import dispatch._ , Defaults._ object Main extends App { //concats a the proper uri together to send to google finance def composeUri ( l:List[String]) = { def google = host("google").secure def googleFinance = google / "finance" / "info" def googleFinanceGet = googleFinance.GET val csv = l mkString "," googleFinanceGet <<? Map("infotype"-> "infoquoteall", "q"->csv) } def sendRequest (uri:Req) = { val res:Future[Either[Throwable,String]] = Http(uri OK as.String).either res } val future = sendRequest(composeUri(List("tsla","goog"))) for (f <- future.left) yield println("There was an error" + f.getMessage) }

谢谢!

推荐答案

如果您打印组合的URL(例如,使用composeUri(List("tsla", "goog")).url),则会发现它与您的工作示例有所不同,其中不包括www子域.将google的定义更改为使用www.google,它将按预期工作.

If you print the composed URL (using composeUri(List("tsla", "goog")).url, for example), you'll see that it's different from your working example—it doesn't include the www subdomain. Change the definition of google to use www.google and this'll work as expected.

更多推荐

Scala调度简单获取请求

本文发布于:2023-11-25 04:18:44,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1628295.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:简单   Scala

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!