如何使用curl客户端证书身份验证上传?(How to upload with curl client certificate authentication?)
除了对上传使用基本或摘要式身份验证之外,服务是否可以生成证书以供客户端下载以进行身份验证的上载? 例如,可以使用Keygen ,尽管在某处“保存证书”可能更为直接。
一旦用户拥有证书,用户就可以通过cURL上传“foobar.png”。 也许是这样的:
curl -E mycert.pem -F "fileupload=@foobar.png" http://example.com/secure-upload.php
有没有人设置类似的计划? 我不确定它是否可行,因为联机帮助页中的
-E
开关未提及POST。 另外,我不确定如何设置httpd服务来验证证书。 希望只是一个Apache SSL指令 。Instead of using basic or digest authentication for an upload, could it be possible for a service to generate a certificate for the client to download for authenticated uploads? Keygen could be used for example, though it might be more straightforward to "Save the certificate" somewhere.
Once the user has the certificate, the user is able to then upload "foobar.png" via cURL. Perhaps like so:
curl -E mycert.pem -F "fileupload=@foobar.png" http://example.com/secure-upload.php
Has anyone setup a similar scheme? I'm not sure it's possible as the
-E
switch in the manpage does not mention POST. Also I am unsure how to setup the httpd service to authenticate the certificate. Hopefully just an Apache SSL directive.
原文:https://stackoverflow.com/questions/909622
最满意答案
通常会将
def
版本编写为:def f2(a:Int) = a+1
如果你按照自己的方式编写它,它实际上是在创建一个方法
f2
,当被调用时,构造一个新的函数闭包。 所以在你的两种情况下,你仍然有一个功能。 但在第一种情况下,函数只构造一次并存储(如f1
)供以后使用。 但在第二种情况下,每次引用f2
都会构造函数,这是一种浪费。那么什么时候比一个方法更喜欢一个函数呢? 那么,在某些情况下,您可以更轻松地使用函数。 考虑这种情况:
(1 to 3).map(f1 andThen f1) // totally fine (1 to 3).map(f2 andThen f1) // "missing arguments" error (1 to 3).map(f2 _ andThen f1) // fixed by adding "_" after the method name
因此
f1
始终是一个函数,因此您可以调用类似于andThen
的方法。 变量f2
代表一种方法,所以它不希望像这样使用; 它总是希望跟随论证。 您可以随后通过下划线将方法转换为函数,但如果没有必要,这可能看起来有点难看。Typically one would write the
def
version as:def f2(a:Int) = a+1
If you write it they way you did, it's actually creating a method
f2
that, when called, constructs a new function closure. So in both of your cases, you still have a function. But in the first case, the function gets constructed only once and stored (asf1
) for later use. But in the second case, the function gets constructed every timef2
is referenced, which is kind of a waste.So when to prefer a function over a method? Well, you can work with a function a bit more easily in certain situations. Consider this case:
(1 to 3).map(f1 andThen f1) // totally fine (1 to 3).map(f2 andThen f1) // "missing arguments" error (1 to 3).map(f2 _ andThen f1) // fixed by adding "_" after the method name
So
f1
is always a function and so you can call a method likeandThen
on it. The variablef2
represents a method, so it doesn't expect to be used like this; it always expects to be followed by arguments. You can always turn a method into a function by following it with an underscore, but this can look a little ugly if it's not necessary.
相关问答
更多-
函数与Scala中的方法(Functions vs methods in Scala)[2021-07-22]
在引擎盖下,功能和方法之间还有其他差异。 一般来说,普通方法比函数产生的开销要小(这在技术上是带有apply方法的对象)。 然而,如果你不去关心这些差异,并把def , val和var成不同语义的字段 ,那么简单的说, def每次调用时都会评估它,而val只评估一次。 因此, val isEven = isDivisibleBy(2)应在其定义期间调用isDivisibleBy(2)并分配isDivisibleBy(2)的结果。 例如,它取代了k def isDivisibleBy(k: Int): Int ... -
谁能解释这个签名? futureUsing[I <: Closeable, R] futureUsing使用两种不同的类型(两种类型参数)。 我们不确切地知道它们是什么类型,但是我们将调用一个I (输入),它是一个(或派生自) Closable ,另一个是R (结果)。 (resourse: I) 对于futureUsing的第一个讨论论点是I型。 我们称之为resourse 。 (f: I => Future[R]) 第二个curried参数f是一个函数,它接受类型I的参数并返回一个将最终包含R类型 ...
-
Scala与Java方法调用(Scala vs Java method invocation)[2023-02-19]
希望我能证明发生了什么: class TheClass { def theMethod:Unit = { println("It's me the method"); } } scala> classOf[TheClass].getDeclaredMethod("theMethod").invoke(new TheClass, null) java.lang.IllegalArgumentException: wrong number of arguments at sun.reflect.N ... -
什么是 '???'(what is '???' in Scala?)[2022-11-01]
??? 被设计为占位符,是Predef定义的方法(默认情况下自动导入) 它的定义是 def ??? : Nothing = throw new NotImplementedError 所以它的返回类型为Nothing ,它所做的就是抛出NotImplementedError 。 此定义允许它用作您定义但尚未实现但仍希望能够编译程序的方法的占位符实现。 Nothing是每种类型的子类型,这使得??? 无论预期的类型是什么,都是有效的实现。 ??? is designed as a placeholder an ... -
概要: 是的,可以在Scala中测试两个具体函数引用之间的相等性,但不完全如您所说明的那样。 您只需捕获对象,类或特征(不是lambda表达式,匿名函数等)的具体函数引用。 细节: 因为Scala确实具有函数引用的概念,所以可以检查两个不同的函数引用以引用相等。 而且由于Scala还提供了一种从任何有效的Scala方法获取函数引用的机制,这意味着你可以做你正在寻找的东西,给出你对mz答案的评论问题,“......没有办法得到一个参考或类似的方法?“ 最重要的是要记住两个函数只能用于参考平等。 IOW,函数不 ...
-
我不能告诉你你做错了什么,但我使用compiler.typedTree在我的项目中获取AST。 也许这也适用于你。 有关更多上下文,请参阅http://scala.ifs.hsr.ch/browser/src/scala/tools/refactoring/util/CompilerProvider.scala 。 I can't tell you what you're doing wrong, but I use compiler.typedTree to get an AST in my projec ...
-
通常会将def版本编写为: def f2(a:Int) = a+1 如果你按照自己的方式编写它,它实际上是在创建一个方法f2 ,当被调用时,构造一个新的函数闭包。 所以在你的两种情况下,你仍然有一个功能。 但在第一种情况下,函数只构造一次并存储(如f1 )供以后使用。 但在第二种情况下,每次引用f2都会构造函数,这是一种浪费。 那么什么时候比一个方法更喜欢一个函数呢? 那么,在某些情况下,您可以更轻松地使用函数。 考虑这种情况: (1 to 3).map(f1 andThen f1) // tota ...
-
cons不是Stream2实例的一部分。 它是Stream2对象的单例(静态)方法。 因此,访问它的唯一方法是通过对象调用它: Stream2.cons(2,s) 要访问实例上的方法,您必须将其添加到trait (因为它引用特征而不是创建的最终对象)。 否则,您可以将其添加到单例并通过它调用它。 cons is not part of the Stream2 instance. It is a singleton(static) method of the Stream2 object. So, the ...
-
您可以在此处使用的一般类型是GenTraversable : scala> def printAll(coll: collection.GenTraversable[_]) = coll.foreach(println) defined function printAll scala> printAll("aaa") a a a scala> printAll(Array(1,2,3)) 1 2 3 scala> printAll(Seq(4,5,6)) 4 5 6 您也不需要迭代器。 您可以更轻松地 ...
-
Scala mapConserve用例(Scala mapConserve use case)[2022-08-25]
这个问题引起了我的兴趣,所以我浏览了Scala代码库并查看了mapConserves()实际用途。 在一些地方弹出的一个是:如果参数是部分函数,轻松跟踪地图操作是否已经进行了实际更改(通过简单的参考检查),就像在Erasure的示例中一样: def squashBoxed(tp: Type): Type = tp.dealiasWiden match { case t @ RefinedType(parents, decls) => val parents1 = parents mapConse ...