使用 Scala 和 Dispatch 进行 HTTPS POST

发布于 2024-11-26 07:53:12 字数 793 浏览 1 评论 0原文

我正在尝试使用 scala 和 Dispatch 库发布 HTTPS 帖子。我找不到在哪里将我的连接标记为 https 而不是 http。这是我到目前为止的代码

println("Running Test")
val http = new Http
val req = :/("www.example.com" , 443) / "full/path.asp"
var response: NodeSeq = Text("")
http(req << "username=x&password=y" <> {response = _ } )
response
println("Done Running Test")

编辑

所以在尝试弄清楚这一点之后,我追踪到了所需的内容,http行需要看起来像这样

http(req.secure << "username=x&password=y" <> {response = _ } )

另外在这个特定的实例中,我需要以 application/x 的形式发布-www-form-urlencoded 要求该行看起来像这样

http(req.secure << ("username=x&password=y","application/x-www-form-urlencoded") <> {response = _ } )

这现在将替换 40 行 C++ + Boost + Asio 代码。

I am trying to do a HTTPS post with scala and the Dispatch library. I can't find where to mark my connection as being https not http. Here is the code I have so far

println("Running Test")
val http = new Http
val req = :/("www.example.com" , 443) / "full/path.asp"
var response: NodeSeq = Text("")
http(req << "username=x&password=y" <> {response = _ } )
response
println("Done Running Test")

EDIT

So After attempting to figure this out I traced down what was needed the http line needs to look like this

http(req.secure << "username=x&password=y" <> {response = _ } )

Also In this specific instance I needed to POST as application/x-www-form-urlencoded that required the line to look like this

http(req.secure << ("username=x&password=y","application/x-www-form-urlencoded") <> {response = _ } )

This will now replace 40 Lines of C++ + Boost + Asio code.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

拥抱没勇气 2024-12-03 07:53:12

因此,在尝试弄清楚这一点之后,我追踪到了需要什么,http行需要看起来像这样

http(req.secure << "username=x&password=y" <> {response = _ } )    

另外,在这个特定的实例中,我需要以 application/x-www-form-urlencoded 的形式发布,要求该行看起来像这样

http(req.secure << ("username=x&password=y","application/x-www-form-urlencoded") <> {response = _ } 

So After attempting to figure this out I traced down what was needed the http line needs to look like this

http(req.secure << "username=x&password=y" <> {response = _ } )    

Also In this specific instance I needed to POST as application/x-www-form-urlencoded that required the line to look like this

http(req.secure << ("username=x&password=y","application/x-www-form-urlencoded") <> {response = _ } 
我是男神闪亮亮 2024-12-03 07:53:12

您可以将“secure”应用于 :/ 工厂:

:/("host").secure

You could apply "secure" to the :/ factory:

:/("host").secure
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文