mirror of
https://github.com/curlconverter/curlconverter.git
synced 2022-05-22 02:35:29 +03:00
Support proxy, proxy-user, max-time, location on PHP (#354)
This commit is contained in:
1
fixtures/curl_commands/get_follow_location.sh
Normal file
1
fixtures/curl_commands/get_follow_location.sh
Normal file
@@ -0,0 +1 @@
|
||||
curl 'http://example.net' -L
|
||||
1
fixtures/curl_commands/get_max_time.sh
Normal file
1
fixtures/curl_commands/get_max_time.sh
Normal file
@@ -0,0 +1 @@
|
||||
curl 'http://example.com' -m 20
|
||||
1
fixtures/curl_commands/get_proxy.sh
Normal file
1
fixtures/curl_commands/get_proxy.sh
Normal file
@@ -0,0 +1 @@
|
||||
curl 'http://localhost:9000' -x 'http://localhost:8080'
|
||||
1
fixtures/curl_commands/get_proxy_with_auth.sh
Normal file
1
fixtures/curl_commands/get_proxy_with_auth.sh
Normal file
@@ -0,0 +1 @@
|
||||
curl 'http://localhost:9000' --proxy 'http://localhost:8080' -U 'anonymous:anonymous'
|
||||
10
fixtures/php/follow_location.php
generated
Normal file
10
fixtures/php/follow_location.php
generated
Normal file
@@ -0,0 +1,10 @@
|
||||
<?php
|
||||
$ch = curl_init();
|
||||
curl_setopt($ch, CURLOPT_URL, 'http://example.net');
|
||||
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
|
||||
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, 'GET');
|
||||
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true);
|
||||
|
||||
$response = curl_exec($ch);
|
||||
|
||||
curl_close($ch);
|
||||
11
fixtures/php/get_digest_auth.php
generated
Normal file
11
fixtures/php/get_digest_auth.php
generated
Normal file
@@ -0,0 +1,11 @@
|
||||
<?php
|
||||
$ch = curl_init();
|
||||
curl_setopt($ch, CURLOPT_URL, 'http://localhost:28139/');
|
||||
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
|
||||
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, 'GET');
|
||||
curl_setopt($ch, CURLOPT_HTTPAUTH, CURLAUTH_DIGEST);
|
||||
curl_setopt($ch, CURLOPT_USERPWD, 'some_username:some_password');
|
||||
|
||||
$response = curl_exec($ch);
|
||||
|
||||
curl_close($ch);
|
||||
10
fixtures/php/get_max_time.php
generated
Normal file
10
fixtures/php/get_max_time.php
generated
Normal file
@@ -0,0 +1,10 @@
|
||||
<?php
|
||||
$ch = curl_init();
|
||||
curl_setopt($ch, CURLOPT_URL, 'http://example.com');
|
||||
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
|
||||
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, 'GET');
|
||||
curl_setopt($ch, CURLOPT_TIMEOUT, 20);
|
||||
|
||||
$response = curl_exec($ch);
|
||||
|
||||
curl_close($ch);
|
||||
10
fixtures/php/get_proxy.php
generated
Normal file
10
fixtures/php/get_proxy.php
generated
Normal file
@@ -0,0 +1,10 @@
|
||||
<?php
|
||||
$ch = curl_init();
|
||||
curl_setopt($ch, CURLOPT_URL, 'http://localhost:9000');
|
||||
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
|
||||
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, 'GET');
|
||||
curl_setopt($ch, CURLOPT_PROXY, 'http://localhost:8080');
|
||||
|
||||
$response = curl_exec($ch);
|
||||
|
||||
curl_close($ch);
|
||||
11
fixtures/php/get_proxy_with_auth.php
generated
Normal file
11
fixtures/php/get_proxy_with_auth.php
generated
Normal file
@@ -0,0 +1,11 @@
|
||||
<?php
|
||||
$ch = curl_init();
|
||||
curl_setopt($ch, CURLOPT_URL, 'http://localhost:9000');
|
||||
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
|
||||
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, 'GET');
|
||||
curl_setopt($ch, CURLOPT_PROXY, 'http://localhost:8080');
|
||||
curl_setopt($ch, CURLOPT_PROXYUSERPWD, 'anonymous:anonymous');
|
||||
|
||||
$response = curl_exec($ch);
|
||||
|
||||
curl_close($ch);
|
||||
@@ -42,7 +42,8 @@ export const _toPhp = request => {
|
||||
}
|
||||
|
||||
if (request.auth) {
|
||||
phpCode += 'curl_setopt($ch, CURLOPT_HTTPAUTH, CURLAUTH_BASIC);\n'
|
||||
const authType = request.digest ? 'CURLAUTH_DIGEST' : 'CURLAUTH_BASIC'
|
||||
phpCode += 'curl_setopt($ch, CURLOPT_HTTPAUTH, ' + authType + ');\n'
|
||||
phpCode += "curl_setopt($ch, CURLOPT_USERPWD, '" + quote(request.auth.join(':')) + "');\n"
|
||||
}
|
||||
|
||||
@@ -58,14 +59,29 @@ export const _toPhp = request => {
|
||||
}
|
||||
}
|
||||
requestDataCode += ']'
|
||||
} else if (request.isDataBinary) {
|
||||
requestDataCode += "file_get_contents('" + quote(request.data.substring(1)) + "')"
|
||||
} else if (request.isDataBinary && request.data.charAt(0) === '@') {
|
||||
requestDataCode = "file_get_contents('" + quote(request.data.substring(1)) + "')"
|
||||
} else {
|
||||
requestDataCode = "'" + quote(request.data) + "'"
|
||||
}
|
||||
phpCode += 'curl_setopt($ch, CURLOPT_POSTFIELDS, ' + requestDataCode + ');\n'
|
||||
}
|
||||
|
||||
if (request.proxy) {
|
||||
phpCode += "curl_setopt($ch, CURLOPT_PROXY, '" + quote(request.proxy) + "');\n"
|
||||
if (request.proxyAuth) {
|
||||
phpCode += "curl_setopt($ch, CURLOPT_PROXYUSERPWD, '" + quote(request.proxyAuth) + "');\n"
|
||||
}
|
||||
}
|
||||
|
||||
if (request.timeout) {
|
||||
phpCode += 'curl_setopt($ch, CURLOPT_TIMEOUT, ' + (parseInt(request.timeout) || 0) + ');\n'
|
||||
}
|
||||
|
||||
if (request.followRedirects) {
|
||||
phpCode += 'curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true);\n'
|
||||
}
|
||||
|
||||
if (request.insecure) {
|
||||
phpCode += 'curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, false);\n'
|
||||
phpCode += 'curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);\n'
|
||||
|
||||
9
util.js
9
util.js
@@ -1132,6 +1132,15 @@ const buildRequest = parsedArguments => {
|
||||
}
|
||||
if (parsedArguments.proxy) {
|
||||
request.proxy = parsedArguments.proxy
|
||||
if (parsedArguments['proxy-user']) {
|
||||
request.proxyAuth = parsedArguments['proxy-user']
|
||||
}
|
||||
}
|
||||
if (parsedArguments['max-time']) {
|
||||
request.timeout = parsedArguments['max-time']
|
||||
}
|
||||
if (parsedArguments.location) {
|
||||
request.followRedirects = true
|
||||
}
|
||||
if (parsedArguments.output) {
|
||||
request.output = parsedArguments.output
|
||||
|
||||
Reference in New Issue
Block a user