shuber / curl Goto Github PK
View Code? Open in Web Editor NEWA basic CURL wrapper for PHP
License: MIT License
A basic CURL wrapper for PHP
License: MIT License
When a url return content by redirect once. The response will have two headers. And the CurlReponse just preg_match one header. and the other exists in the $reponse->body. I thought it's a bug.
Thank U.
Hello! Seems there is a problem with HTTP/2 request. The pattern in the preg regex isn't able to detect the new HTTP/2 response. Maybe the pattern needs to be updated or a check for which version was sent to check the response.
In case Curl is used on Windows, it may be required to pass a certificate to the curl command like so :
In the set_request_options()
method, found in the Curl
class
// Add certificate for Windows
if (strtoupper(substr(PHP_OS, 0, 3)) === 'WIN') {
curl_setopt($this->request, CURLOPT_CAINFO, dirname(FILE) . DIRECTORY_SEPARATOR . 'Curl' . DIRECTORY_SEPARATOR . 'cacert.pem');
}
By the way, many thanks for this repo ;)
Hello. Is there any way to detect if a curl POST timeouts?
if ($response) {
$response = new CurlResponse($response);
$response->info = curl_getinfo($this->request);
} else {
$this->error = curl_errno($this->request).' - '.curl_error($this->request);
}
Can you please release a version so folks aren't required to use dev-master
?
Hi shuber, thanks for this useful wrapper.
Have you considered adding namespaces on it? Following any standard like PSR-0 would be great.
When a request is completed following a redirect, the curl response contains the headers from the first and the second requests. In this case not all the headers are removed, only the last one is stripped from the response, resulting in a body containing the other headers.
HTTP/1.1 302 Found
Location: http://www.google.es/
Cache-Control: private
Content-Type: text/html; charset=UTF-8
Date: Tue, 20 Dec 2011 10:54:50 GMT
Server: gws
Content-Length: 218
X-XSS-Protection: 1; mode=block
X-Frame-Options: SAMEORIGIN
HTTP/1.1 200 OK
Date: Tue, 20 Dec 2011 10:54:50 GMT
Expires: -1
Cache-Control: private, max-age=0
Content-Type: text/html; charset=ISO-8859-1
Server: gws
X-XSS-Protection: 1; mode=block
X-Frame-Options: SAMEORIGIN
Transfer-Encoding: chunked
Hi shuber,
I have an upload api i use it to upload files to google cloud storage and this is the api
http://acquired-backup-198200.appspot.com/upload?uname=arun&Description=description&players=arun,sai&community=true&Location=US&skills=batting&analysis=true
I use php-curl to upload files to this api and this is the php code
`if( $_SERVER['REQUEST_METHOD'] == 'POST' ){
$file = $_FILES['files'];
$fileName = $file['name'];
$fileType = $file['type'];
$fileTmp = $file['tmp_name'];
var_dump( $file );
$curl = curl_init();
curl_setopt_array($curl, array(
CURLOPT_URL => "http://acquired-backup-198200.appspot.com/upload?uname=arun&Description=description&players=arun,sai&community=true&Location=US&skills=batting&analysis=true",
CURLOPT_RETURNTRANSFER => true,
CURLOPT_ENCODING => "",
CURLOPT_MAXREDIRS => 10,
CURLOPT_TIMEOUT => 30,
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
CURLOPT_CUSTOMREQUEST => "POST",
CURLOPT_POSTFIELDS => "------WebKitFormBoundary7MA4YWxkTrZu0gW\r\nContent-Disposition: form-data; name=\"filename\"; filename=\"". $fileName ."\"\r\nfile=\"filedir\"; filedir=\"@/home/alaa/Desktop/Cielo_estrellado_by_Eduardo_Diez_Viñuela.jpg\"\r\nContent-Type: image/jpeg\r\n\r\n\r\n------WebKitFormBoundary7MA4YWxkTrZu0gW--",
CURLOPT_HTTPHEADER => array(
"Cache-Control: no-cache",
"content-type: multipart/form-data; boundary=----WebKitFormBoundary7MA4YWxkTrZu0gW"
),
));
$response = curl_exec($curl);
$err = curl_error($curl);
curl_close($curl);
if ($err) {
echo "cURL Error #:" . $err;
} else {
echo $response;
};
}`
And this is html
<form method="post" enctype="multipart/form-data"> <input type="file" name="files"> <input type="submit" name=""> </form>
The process succeed but the files in the storage are 0 bytes size so can you help me in that problem please?
hi,
When i make a command line curl -d "data=plop" url
, my server running php script get the $_POST
filed with data=plop
but when i use your library, i must make a file_get_content(php://input)
to get the data.
Why ? :(
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.