标签: curl

CURL中的自定义IP

这不起作用.请帮忙!

curl_setopt($ch, CURLOPT_HTTPHEADER, array("REMOTE_ADDR: $ip", "HTTP_X_FORWARDED_FOR: $ip"));
Run Code Online (Sandbox Code Playgroud)

php curl

-1
推荐指数
1
解决办法
3991
查看次数

如何检测,直接访问或通过CURL访问的URL

// remote.php on http://www.example.com/
<?php
function curl_access()
{ /*
  some codes here to detect
  this script accessed via
  curl or direct and returns $r.
  (without checking referrer or user agent)
  */
  return $r;
}
$curl_access = curl_access();
if ($curl_access)
{ echo 'Accessed via CURL';
} else
{ echo 'Direct access';
}
?>

// some file on a server
<?php
$h = curl_init();
curl_setopt($c, CURLOPT_URL, "http://www.example.com/remote.php");
curl_exec($c); // returns 'Accessed via CURL'
curl_close($c);
?>
Run Code Online (Sandbox Code Playgroud)

php curl

-1
推荐指数
1
解决办法
2409
查看次数

如何使用cURL查找包含特定字符串的子域?

我正在尝试在ghix.com上建立一个所有城市页面的列表,它没有这么完整的目录.要做到这一点,我使用他们的'城市id',这是每个城市独有的,但不遵循任何特定的顺序.

我正在使用cURL和PHP来遍历可能的域以搜索与实际城市匹配的域.很简单.请参阅下面的代码,它会产生500内部服务错误.

如果有效,输出应该是与实际城市不匹配的"城市ID"列表.如果URL与实际城市匹配,则页面上不会有(0),但如果它与城市不匹配,则页面上将显示(0).

我已经多次查看并纠正了这个错误导致了什么?

<html>
<?php
for ($i = 1; ; $i <= 1000000; $i++) {
  $url = "http://www.ghix.com/goto/dynamic/city?CityID=" . $i;
  $term="(0)";
  curl_setopt($ch, CURLOPT_URL, trim($url));
  $html = curl_exec($ch);
  if ($html !== FALSE && stristr($html, $term) !== FALSE) { // Found!
    echo $i;
    Echo "br/";
  } 
}
?>
</html>
Run Code Online (Sandbox Code Playgroud)

更新我试过的一种略有不同的方法,效果相同......

<html>
<?php

for ($i = 1; $i <= 100; $i++) {
$url = "http://www.ghix.com/goto/dynamic/city?CityID=" . $i;
$term="(0)";
curl_setopt($ch, CURLOPT_URL, trim($url));
$html = curl_exec($ch);
if (strpos($ch,$term)) {
    echo …
Run Code Online (Sandbox Code Playgroud)

html php string curl loops

-1
推荐指数
1
解决办法
575
查看次数

如何使用 PHP 在 curl 中使用变量传递 http 标头

我添加标题的代码是:

$apikey="xyz";
     curl_setopt($handle, CURLOPT_HTTPHEADER, array(
                                            'Content-Type: application/json',
                                            'Accept: application/json',
                                            'X-Auth-Token: $apikey'                                 
                                            ));
Run Code Online (Sandbox Code Playgroud)

但我收到一条错误消息,表明 **此请求需要 HTTP 身份验证。**现在我想知道我是否正确?如果是,为什么我会出错。如果我错了,我该怎么做..

谢谢,

php curl

-1
推荐指数
1
解决办法
2172
查看次数

如何使用awk解析网址并传递给curl下载呢?

我想从https://github.com/sschwartzman/newrelic-unix-plugin下载二进制文件.但是url会重定向到另一个地址,所以我使用awk来解析它.例如

curl -I https://github.com/sschwartzman/newrelic-unix-plugin/blob/master/dist/newrelic_unix_plugin.tar.gz\?raw\=true | awk '/Location:/ {print $2}'
Run Code Online (Sandbox Code Playgroud)

结果如我所料,例如

  % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current
                                 Dload  Upload   Total   Spent    Left  Speed
  0     0    0     0    0     0      0      0 --:--:--  0:00:01 --:--:--     0
https://github.com/sschwartzman/newrelic-unix-plugin/raw/master/dist/newrelic_unix_plugin.tar.gz
Run Code Online (Sandbox Code Playgroud)

解析实际地址.所以我只想用curl下载它.但我总是失败.我的操作系统是osx El Capitan(我没有wget).

curl -I https://github.com/sschwartzman/newrelic-unix-plugin/blob/master/dist/newrelic_unix_plugin.tar.gz\?raw\=true | awk '/Location:/ {curl -O $2}'
Run Code Online (Sandbox Code Playgroud)

ps我试图直接通过curl下载二进制文件,但仍然失败了.下载的文件大小和内容不正确.

curl -O https://github.com/sschwartzman/newrelic-unix-plugin/raw/master/dist/newrelic_unix_plugin.tar.gz
Run Code Online (Sandbox Code Playgroud)

bash awk curl

-1
推荐指数
1
解决办法
363
查看次数

在bash,curl,grep序列之后,我如何回应"通过"或"失败"?

我是优雅单行的忠实粉丝.我正在尝试编写一个单行测试,在执行http请求和搜索后输出"pass"或"fail".我尝试过这样的事情:

curl "http://haystack.io" | sed 's/.*?needle.*/PASS/' || echo FAIL
Run Code Online (Sandbox Code Playgroud)

......但这不会失败.

还尝试过:

curl "http://haystack.io" | if [$(grep -oE "needle") = "needle"]; then echo PASS; else echo FAIL; fi
Run Code Online (Sandbox Code Playgroud)

...但我无法正确理解语法.

我怎样才能做到这一点?

macos bash grep curl sed

-1
推荐指数
1
解决办法
367
查看次数

CURL 在 php 中不起作用

在我的应用程序中,我使用 Commercetools API。

为了从他们的 API 获取数据,我需要调用一个端点。

以下是我用来获取产品的端点。

https://api.sphere.io/vc-1209/products -H "Authorization: Bearer -5DVqQFgkd_SDGthsFgtepS"
Run Code Online (Sandbox Code Playgroud)

当我在终端中运行上面的 URL 时,例如

curl https://api.sphere.io/vc-1209/products -H "Authorization: Bearer -5DVqQFgkd_SDGthsFgtepS"
Run Code Online (Sandbox Code Playgroud)

它给了我所有产品的回应。

但是当我从 PHP 的 cURL 执行相同的 URL 时,它不起作用。

$url = 'https://api.sphere.io/vc-1209/products -H "Authorization: Bearer -5DVqQFgkd_SDGthsFgtepS"';

$curl = curl_init($url);
curl_setopt($curl, CURLOPT_POST, TRUE);
curl_setopt($curl, CURLOPT_RETURNTRANSFER, TRUE);
$response = curl_exec($curl);

print_r($response);
Run Code Online (Sandbox Code Playgroud)

我回来了:

客户端发送了错误的请求。

php curl commercetools

-1
推荐指数
1
解决办法
2332
查看次数

如何使用cURL在php中发布表单数据?

我有以下命令,该命令使用--form /-F选项,该命令我知道它可以正常工作:

curl  --form "file=@/home/USERNAME/import.csv" https://apiprovider.com/api/v0/imports\?token\=[KEY]
Run Code Online (Sandbox Code Playgroud)

我需要通过php运行此命令,但是我遇到了麻烦,大概是表单文件数据。我尝试了以下操作,但是echo或var_dumping结果似乎什么也没显示,只是空白页或空白字符串。

<?php 
$target_url = 'https://apiprovider.com/api/v0/imports?token=[KEY]'
$file_name_with_full_path ='/home/USERNAME/import.csv';
$post = array('file'=>'@'.$file_name_with_full_path);

$ch = curl_init();
curl_setopt($ch, CURLOPT_URL,$target_url);
curl_setopt($ch, CURLOPT_POST,1);
curl_setopt($ch, CURLOPT_POSTFIELDS, $post);
curl_setopt($ch, CURLOPT_RETURNTRANSFER,1);
curl_setopt($ch, CURLOPT_VERBOSE,true);
$result=curl_exec ($ch);
curl_close ($ch);
var_dump($result);?>
Run Code Online (Sandbox Code Playgroud)

如何在PHP中使用此命令?

php curl

-1
推荐指数
1
解决办法
5427
查看次数

如何在std :: string中保存curl下载?

我知道我可以从c ++程序调用system("curl path-LJO")来下载文件并将其保存在当前目录中然后我可以使用STL将它保存到std :: string.但有没有办法直接将它保存在std :: string中?我知道abot https://github.com/curl/curl但我想知道:curl命令中的任何说明符都是这样做的吗?如果没有,最好的办法是什么?

c++ curl

-1
推荐指数
1
解决办法
80
查看次数

在 ubuntu pod 中找不到 curl 或 sudo 包

我在 kubernetes 上部署了一个服务,然后我想在集群本身内部测试它,然后再设置入口规则以在外部访问它。

因此,在我从日志中验证该服务正在运行之后。

我尝试创建一个 Pod 并通过以下方式访问其中的 shell

kubectl run -i --tty ubuntu --image=ubuntu --restart=Never -- sh

这似乎工作正常。我看到了一个 ubuntu shell,它似乎运行良好。

但是如果我做一个卷曲:例如

curl --location --request GET 'http://127.0.0.1:9000/hello'

我得到回应 sh: 4: curl: not found

所以后来我尝试了,

apt-get install curl 这给了我:

Reading package lists... Done
Building dependency tree
Reading state information... Done
E: Unable to locate package curl
Run Code Online (Sandbox Code Playgroud)

认为这是因为 sudo 。我就是这么做的sudo apt-get install curl,但这告诉我 sh: 6: sudo: not found

尝试安装 sudoapt-get install sudo但那只是给出

Reading package lists... Done
Building dependency tree …
Run Code Online (Sandbox Code Playgroud)

ubuntu curl sudo apt-get kubernetes

-1
推荐指数
1
解决办法
3915
查看次数

标签 统计

curl ×10

php ×6

bash ×2

apt-get ×1

awk ×1

c++ ×1

commercetools ×1

grep ×1

html ×1

kubernetes ×1

loops ×1

macos ×1

sed ×1

string ×1

sudo ×1

ubuntu ×1