cURL无法正常工作!(cURL not working correct!)
我有一个关于cURL的问题。 我正在使用cURL这个函数:
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true);
只有这导致错误:“消息:curl_setopt()[function.curl-setopt]:当在safe_mode或open_basedir设置时,无法激活CURLOPT_FOLLOWLOCATION”
所以我要求我的托管服务提供商解决这个问题,他们做到了。 但是,这真的很愚蠢,他们在我的bin目录中放了一个“curl”文件。 我不知道如何在我的PHP脚本中包含这个:S。
从来没有做过,但任何人都可以帮助我。 我真的被卡住了。 我希望我发布足够的信息!
Tnx在先进!
Tnx为所有伟大的回复。 但是我如何在这段代码中使用“exec()”?
// create a new cURL resource $ch = curl_init(); // set URL and other appropriate options curl_setopt($ch, CURLOPT_USERAGENT, "Mozilla/4.0 (compatible; MSIE 5.01; Windows NT 5.0)"); curl_setopt($ch, CURLOPT_RETURNTRANSFER, TRUE); curl_setopt($ch, CURLOPT_TRANSFERTEXT, TRUE); curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 30); curl_setopt($ch, CURLOPT_URL, $articleUrl); curl_setopt($ch, CURLOPT_HEADER, 0); curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true); curl_setopt($ch, CURLOPT_MAXREDIRS, 5); // grab URL and pass it to $grabArticle $grabArticle = curl_exec($ch);
编辑2:好的,我几乎让它工作:)。 当我在putty中运行它时工作正常,但在我的php脚本中没有任何反应:(
我运行这个:
$grabArticle = exec('/home/twittern/bin/curl -L -m 30 -w url_effective --max-redirs 5 http://fok.nl/415758'); echo $grabArticle;
我做错了什么?
I have a question about cURL. I am using cURL with this function:
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true);
Only this was causing an error: "Message: curl_setopt() [function.curl-setopt]: CURLOPT_FOLLOWLOCATION cannot be activated when in safe_mode or an open_basedir is set"
So I asked my hosting provider to fix this, and they did. But, and this is really stupid, they put a "curl" file in my bin directory. And I have no idea how to include this in my php script :S.
Never done it before, but can anybody help me. I am really stuck. I hope I posted enough info!
Tnx in advanced!
Tnx for all the great replies. But How would I fit "exec()" in this code?
// create a new cURL resource $ch = curl_init(); // set URL and other appropriate options curl_setopt($ch, CURLOPT_USERAGENT, "Mozilla/4.0 (compatible; MSIE 5.01; Windows NT 5.0)"); curl_setopt($ch, CURLOPT_RETURNTRANSFER, TRUE); curl_setopt($ch, CURLOPT_TRANSFERTEXT, TRUE); curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 30); curl_setopt($ch, CURLOPT_URL, $articleUrl); curl_setopt($ch, CURLOPT_HEADER, 0); curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true); curl_setopt($ch, CURLOPT_MAXREDIRS, 5); // grab URL and pass it to $grabArticle $grabArticle = curl_exec($ch);
Edit 2: Oké, I almost got it working :). It is working just fine when I run it in putty, but in my php script nothing happens :(
I run this:
$grabArticle = exec('/home/twittern/bin/curl -L -m 30 -w url_effective --max-redirs 5 http://fok.nl/415758'); echo $grabArticle;
Any thing I am doing wrong?
原文:https://stackoverflow.com/questions/4219340
最满意答案
除了kongo2002:
->
链中的最后一项是return type
, 而不是另一个参数。 第一个接受两个浮点数并返回一个浮点数,第二个接受一个浮点数并返回一个浮点数。这样做的想法,而不是像
(float, float) : float
,是你可以使用一个名为“currying”的概念。generatePowerOfFunc
的类型为float -> float -> float
,它相当于float -> (float -> float)
,所以我们可以给它一个float并返回一个float -> float
类型的函数float -> float
(我们可以给出它是另一个浮子,然后回到浮子上)。这意味着当您调用
generatePowerOfFunc 2. 4.
,您应用两次 。 一旦你申请2.
,一旦你申请4.
。In addition to kongo2002:
The last item in the
->
chain is thereturn type
, not another argument. The first accepts two floats and returns a float, and the second accepts one float and returns one.The idea of doing it like that, and not something like
(float, float) : float
, is that you can use a concept called "currying".generatePowerOfFunc
is of typefloat -> float -> float
, which is equivalent tofloat -> (float -> float)
, so we can give it a single float and get back a function of typefloat -> float
(and we can give it another float, and get back a float).This means that when you call
generatePowerOfFunc 2. 4.
, you apply twice. Once you apply2.
, and once you apply4.
.
相关问答
更多-
这基本上是F#Formatting的Library文档部分 。 它从已编译的DLL(以及XML注释)生成文档,但关键部分是它从已编译的DLL中加载有关F#代码的元数据。 它的工作方式是它使用F#编译器服务来构建项目 它使用F#编译器服务来加载已编译的F#DLL(就像在编译某些代码时引用它一样)。 然后,F#编译器服务会查看有关DLL的所有信息,包括别名(这就是F#编译器在引用DLL时看到的内容!) 它的源代码在GitHub上 - 良好的起点是在这里调用FSharpAssembly.LoadFiles ,它读 ...
-
为什么F#不知道要调用哪一个? F#中的重载分辨率通常比C#更有限。 为了安全起见,F#编译器通常会拒绝C#编译器认为有效的重载。 但是,这个具体案例是一个真正的含糊不清。 为了.NET interop的利益,F#编译器为lambda表达式提供了一个特殊的规定:通常,lambda表达式将编译为F#函数,但如果期望的类型已知为Func<_,_> ,编译器将将lambda转换为.NET委托。 这使我们可以使用基于高阶函数构建的.NET API,例如IEnumerable<_> (又名LINQ),无需手动转换每个 ...
-
通用lambda方法签名(Generic lambda method signature)[2022-04-09]
当然,这是可能的。 你应该有实现 class ThreadedMethods { public static void Parameterized(Action action) { // Start the action on a different thread using possibly ThreadPool.QueueUserWorkItem } } 然后,如您在问题中显示的示例所示,您可以调用您的实现。 编辑:有关如何在有Action时调用Thread ... -
F#Lambda签名(F# Lambda Signature)[2022-12-27]
除了kongo2002: ->链中的最后一项是return type , 而不是另一个参数。 第一个接受两个浮点数并返回一个浮点数,第二个接受一个浮点数并返回一个浮点数。 这样做的想法,而不是像(float, float) : float ,是你可以使用一个名为“currying”的概念。 generatePowerOfFunc的类型为float -> float -> float ,它相当于float -> (float -> float) ,所以我们可以给它一个float并返回一个float -> fl ... -
F#中的C#lambda(=>)语法(C# lambda (=>) syntax in F#)[2022-12-08]
不,这是不可能的,因为lambda运算符绑定了一个变量(左侧是一个变量,或者任何模式匹配,而不是对应于某个值的表达式),所以解析器会对其进行特殊处理。 No, it is not possible, because the lambda operator binds a variable (the left side is a variable, or any pattern matching, not an expression corresponding to a value), it's has sp ... -
总结并从评论中扩展: Per [expr.prim.lambda] / 3, lambda-expression的类型是类类型,就像“普通的,命名的函数对象类型”一样: lambda表达式的类型(也是闭包对象的类型)是一个唯一的,未命名的非联合类类型 - 称为闭包类型 [...] 再往下,/ 5指定: lambda表达式的闭包类型有一个公共inline函数调用操作符(13.5.4),其参数和返回类型分别由lambda-expression的parameter-declaration-clause和trail ...
-
答案是不。 如果你有一个像下面这样的函数,lambdas不会被内联。 在下面的代码中,使用FSharpFunc<,>.InvokeFast()调用FSharpFunc<,>.InvokeFast() let fold f s l = let rec loop acc l = match l with []->acc |h::t->loop (f acc h) t loop s l let list = [1;2;3;4] list|>fold (fun acc x->x ...
-
这是未经测试的,因为我没有SharePoint服务器,但...... open System.Linq.Expressions type Expr = static member Quote(e:Expression
>) = e 允许你从F#lambdas中创建Linq表达式,但是你还需要在lambda参数上给出类型注释,并将返回类型转换为'obj'以匹配预期的签名。 如果需要重用相同的表达式,那么定义一些简短的辅助函数就可以了。 let getTitle = ... -
对未来读者的澄清 :这个答案是在原始问题更新之前编写的。 最初的问题是: 与OCaml不同,F#签名大多没用,因为F#没有仿函数吗? F#签名的用例是什么? 虽然F#没有OCaml模块和仿函数,但它确实有接口和对象,它们提供类似的功能,但功能有限。 这些确实需要类型签名,因为类型推断不适用于它们。 例如: type MyIntf = abstract member m : sting -> int let f i = i.m "hello" // ^ error: cannot lookup ...
-
好吧,表达fun() -> 2是一个函数 。 不是一个数字,也不是一个字符串,不是一个字节数组,而是一个函数 。 对函数唯一要做的就是调用它。 换句话说, 执行它。 调用它。 这就是你用a()做的事情。 你传递给它一个参数() (是的,在F#中的两个括号是F#中的一个实际的东西,你可以将它作为参数传递),并且该函数运行并返回结果。 这是2 。 一个号码。 所以,再一次:首先你有一个功能。 然后你执行它。 该执行的结果是一个数字。 现在,如果你想把一个函数乘以三...你是什么意思? 这有点荒谬。 你的意思是它 ...