标签: curl

如何找到使用cURL重定向的位置?

我正在尝试使curl遵循重定向,但我不能让它正常工作.我有一个字符串,我想作为GET参数发送到服务器并获取结果URL.

例:

String = Kobold Vermin
Url = www.wowhead.com/search?q=Kobold+Worker

如果您转到该网址,它会将您重定向到"www.wowhead.com/npc=257".我希望curl将此URL返回到我的PHP代码,以便我可以提取"npc = 257"并使用它.

当前代码:

function npcID($name) {
    $urltopost = "http://www.wowhead.com/search?q=" . $name;
    $ch = curl_init();
    curl_setopt($ch, CURLOPT_USERAGENT, "Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.8.1.1) Gecko/20061204 Firefox/2.0.0.1");
    curl_setopt($ch, CURLOPT_URL, $urltopost);
    curl_setopt($ch, CURLOPT_REFERER, "http://www.wowhead.com");
    curl_setopt($ch, CURLOPT_HTTPHEADER, Array("Content-Type:application/x-www-form-urlencoded"));
    curl_setopt($ch, CURLOPT_FOLLOWLOCATION, TRUE);
    return curl_getinfo($ch, CURLINFO_EFFECTIVE_URL);
}
Run Code Online (Sandbox Code Playgroud)

然而,这将返回www.wowhead.com/search?q=Kobold+Worker而不是www.wowhead.com/npc=257.

我怀疑在外部重定向发生之前PHP正在返回.我怎样才能解决这个问题?

php redirect curl

146
推荐指数
5
解决办法
25万
查看次数

使用curl POST和bash脚本函数中定义的变量

当我回音时,我得到了这个,当我将它输入终端时运行

curl -i \
-H "Accept: application/json" \
-H "Content-Type:application/json" \
-X POST --data '{"account":{"email":"akdgdtk@test.com","screenName":"akdgdtk","type":"NIKE","passwordSettings":{"password":"Starwars1","passwordConfirm":"Starwars1"}},"firstName":"Test","lastName":"User","middleName":"ObiWan","locale":"en_US","registrationSiteId":"520","receiveEmail":"false","dateOfBirth":"1984-12-25","mobileNumber":"9175555555","gender":"male","fuelActivationDate":"2010-10-22","postalCode":"10022","country":"US","city":"Beverton","state":"OR","bio":"This is a test user","jpFirstNameKana":"unsure","jpLastNameKana":"ofthis","height":"80","weight":"175","distanceUnit":"MILES","weightUnit":"POUNDS","heightUnit":"FT/INCHES"}' https://xxx:xxxxx@xxxx-www.xxxxx.com/xxxxx/xxxx/xxxx
Run Code Online (Sandbox Code Playgroud)

但是当在bash脚本文件中运行时,我收到此错误

curl: (6) Could not resolve host: application; nodename nor servname provided, or not known
curl: (6) Could not resolve host: is; nodename nor servname provided, or not known
curl: (6) Could not resolve host: a; nodename nor servname provided, or not known
curl: (6) Could not resolve host: test; nodename nor servname provided, or not known
curl: (3) [globbing] …
Run Code Online (Sandbox Code Playgroud)

bash json curl javascript-objects

144
推荐指数
8
解决办法
20万
查看次数

如何在cygwin上安装cURL?

我试图在cygwin上启用curl,但它说 bash: curl: command not found

如何在cygwin上安装curl?

curl cygwin

142
推荐指数
6
解决办法
19万
查看次数

使用curl POST多部分/表单数据的正确方法是什么?

我使用这种语法发布文件以及一些参数:

curl -v -include --form "key1=value1" --form upload=localfilename URL
Run Code Online (Sandbox Code Playgroud)

该文件大小约为500K.首先,我看到发送端的内容长度为254.之后服务器响应的内容长度为0.我哪里错了?

这是命令的完整跟踪.

* Couldn't find host xxx.xxx.xxx.xxx in the _netrc file; using defaults
* About to connect() to xxx.xxx.xxx.xxx port yyyy (#0)
*   Trying xxx.xxx.xxx.xxx...
* Adding handle: conn: 0x4b96a0
* Adding handle: send: 0
* Adding handle: recv: 0
* Curl_addHandleToPipeline: length: 1
* - Conn 0 (0x4b96a0) send_pipe: 1, recv_pipe: 0
* Connected to xxx.xxx.xxx.xxx (xxx.xxx.xxx.xxx) port yyyy (#0)
* POST /zzzzzz/UploadFile HTTP/1.1
* User-Agent: curl/7.32.0
* Host: xxx.xxx.xxx.xxx:yyyy …
Run Code Online (Sandbox Code Playgroud)

forms post curl

139
推荐指数
3
解决办法
15万
查看次数

Node.js中的cURL等效?

我正在寻找使用Node.js的HTTP请求中的信息(即调用远程Web服务并回应客户端的响应).

在PHP中我会用cURL来做这件事.Node中的最佳实践是什么?

curl node.js

135
推荐指数
9
解决办法
19万
查看次数

如何使用python执行curl命令

我想在python中执行curl命令.

通常,我只需要在终端输入命令并按回车键.但是,我不知道它在python中是如何工作的.

该命令如下所示:

curl -d @request.json --header "Content-Type: application/json" https://www.googleapis.com/qpxExpress/v1/trips/search?key=mykeyhere
Run Code Online (Sandbox Code Playgroud)

有一个request.json文件要发送以获得响应.

我经常搜索并感到困惑.我试着写一段代码,虽然我无法完全理解.它没用.

import pycurl
import StringIO

response = StringIO.StringIO()
c = pycurl.Curl()
c.setopt(c.URL, 'https://www.googleapis.com/qpxExpress/v1/trips/search?key=mykeyhere')
c.setopt(c.WRITEFUNCTION, response.write)
c.setopt(c.HTTPHEADER, ['Content-Type: application/json','Accept-Charset: UTF-8'])
c.setopt(c.POSTFIELDS, '@request.json')
c.perform()
c.close()
print response.getvalue()
response.close()
Run Code Online (Sandbox Code Playgroud)

错误信息是'Parse Error'.任何人都可以告诉我如何修复它?或者如何正确地从服务器获得响应?

python curl

135
推荐指数
8
解决办法
38万
查看次数

如何捕获PHP中的curl错误

我正在使用PHP curl函数从我的本地计算机将数据发布到Web服务器.我的代码如下:

$c = curl_init();
curl_setopt($c, CURLOPT_URL, $url);
curl_setopt($c, CURLOPT_RETURNTRANSFER, true);
curl_setopt($c, CURLOPT_POST, true);
curl_setopt($c, CURLOPT_POSTFIELDS, $data);
$result = curl_exec($c);
if (curl_exec($c) === false) {
    echo "ok";
} else {
    echo "error";
}
curl_close($c);
Run Code Online (Sandbox Code Playgroud)

不幸的是,我无法捕获404,500或网络故障等任何错误.那么我怎样才能知道数据没有发布到遥控器或从遥控器中检索?

php curl

130
推荐指数
4
解决办法
22万
查看次数

什么是更好,卷曲或wget?

它们是否相同?某些事情可以用一个而不是另一个完成吗?那些是什么?或者,在一天结束时,是熟悉的问题?

linux curl wget

127
推荐指数
4
解决办法
7万
查看次数

如何在使用curl时正确处理gzip压缩页面?

我编写了一个bash脚本,它使用curl从一个网站输出,并在html输出上做了一堆字符串操作.问题是当我针对返回其输出gzip的网站运行它时.在浏览器中访问该网站工作正常.

当我手动运行curl时,我得到gzipped输出:

$ curl "http://example.com"
Run Code Online (Sandbox Code Playgroud)

这是该特定网站的标题:

HTTP/1.1 200 OK
Server: nginx
Content-Type: text/html; charset=utf-8
X-Powered-By: PHP/5.2.17
Last-Modified: Sat, 03 Dec 2011 00:07:57 GMT
ETag: "6c38e1154f32dbd9ba211db8ad189b27"
Expires: Sun, 19 Nov 1978 05:00:00 GMT
Cache-Control: must-revalidate
Content-Encoding: gzip
Content-Length: 7796
Date: Sat, 03 Dec 2011 00:46:22 GMT
X-Varnish: 1509870407 1509810501
Age: 504
Via: 1.1 varnish
Connection: keep-alive
X-Cache-Svr: p2137050.pubip.peer1.net
X-Cache: HIT
X-Cache-Hits: 425
Run Code Online (Sandbox Code Playgroud)

我知道返回的数据是gzip压缩的,因为这会返回html,如预期的那样:

$ curl "http://example.com" | gunzip
Run Code Online (Sandbox Code Playgroud)

我不想通过gunzip管道输出,因为脚本在其他站点上按原样运行,并且通过gzip管道将破坏该功能.

我试过的

  1. 更改用户代理(我尝试了我的浏览器发送的相同字符串,"Mozilla/4.0"等)
  2. 男人卷曲
  3. 谷歌搜索
  4. 搜索stackoverflow

一切都空了

有任何想法吗?

bash curl gzip

123
推荐指数
1
解决办法
7万
查看次数

如何通过代理使用CURL?

我想设置curl使用代理服务器.网址由html表单提供,这不是问题.没有代理,它工作正常.我在这个和其他网站上找到了代码,但它们不起作用.任何帮助找到正确的解决方案将非常感激.我觉得波纹管很接近,但我错过了一些东西.谢谢.

我在这里改编的波纹管代码http://www.webmasterworld.com/forum88/10572.htm,但它返回了第12行丢失的T_VARIABLE的错误消息.

<?

$url = '$_POST[1]';
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL,$url);
curl_setopt($ch, CURLOPT_HTTPPROXYTUNNEL, 0);
curl_setopt($ch, CURLOPT_PROXY, '66.96.200.39:80');
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 0);
curl_setopt($ch, CURLOPT_CUSTOMREQUEST,'GET');
curl_setopt ($ch, CURLOPT_HEADER, 1)
curl_exec ($ch); 
$curl_info = curl_getinfo($ch);
curl_close($ch);
echo '<br />';
print_r($curl_info);
?>
Run Code Online (Sandbox Code Playgroud)

波纹管从卷曲到代理返回没有内容

<?

$proxy = "66.96.200.39:80";
$proxy = explode(':', $proxy);
$url = "$_POST[1]";

$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_PROXY, $proxy[0]);
curl_setopt($ch, CURLOPT_PROXYPORT, $proxy[1]);
curl_setopt($ch, CURLOPT_HEADER, 1);

$exec = curl_exec($ch);

echo curl_error($ch);
print_r(curl_getinfo($ch));
echo …
Run Code Online (Sandbox Code Playgroud)

php proxy curl php-curl

121
推荐指数
2
解决办法
29万
查看次数

标签 统计

curl ×10

php ×3

bash ×2

cygwin ×1

forms ×1

gzip ×1

javascript-objects ×1

json ×1

linux ×1

node.js ×1

php-curl ×1

post ×1

proxy ×1

python ×1

redirect ×1

wget ×1