Fixed curl trouble (linebreak in url file)

This commit is contained in:
xdrm-brackets 2017-01-31 19:26:32 +01:00
parent 74e7d85da9
commit 166fbd3797
1 changed files with 9 additions and 23 deletions

View File

@ -14,6 +14,9 @@
return 127; return 127;
} }
// remove unwanted spaces or linebreaks
$url = preg_replace('/\s/', '', $url);
/* (2) Fetch cyclic hash */ /* (2) Fetch cyclic hash */
$hash = syscall(SOURCE_DIR.'/lib/cyclic-hash/hash'); $hash = syscall(SOURCE_DIR.'/lib/cyclic-hash/hash');
@ -67,35 +70,18 @@
if( strlen($new) == 128 ) if( strlen($new) == 128 )
$postarray['renew'] = $new; $postarray['renew'] = $new;
/* (3) Parse postfiels to multipart format */ /* (3) Set postdata raw to curl */
$postraw = "--$boundary"; curl_setopt($curl, CURLOPT_POSTFIELDS, $postarray);
foreach($postarray as $postkey=>$postvalue)
$postraw .= "\r\nContent-Disposition: form-data; name=\"$postkey\"\r\n\r\n$postvalue\r\n--$boundary";
$postraw .= "--";
/* (4) Set postdata raw to curl */ /* [4] Send and catch request response
curl_setopt($curl, CURLOPT_POSTFIELDS, $postraw);
/* [4] Manage headers
=========================================================*/
curl_setopt($curl, CURLOPT_HTTPHEADER, [
"Content-Type: multipart/form-data; boundary=$boundary"
]);
/* [5] Send and catch request response
=========================================================*/ =========================================================*/
/* (1) Send and catch response */ /* (1) Send and catch response */
curl_setopt($curl, CURLOPT_RETURNTRANSFER, true); curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
$response = curl_exec($curl); $response = curl_exec($curl);
/* (2) Close request */ /* (2) Close request */
curl_close($curl); //curl_close($curl);
/* (3) Return response as result */ /* (3) Return response as result */
if( $response === false ){ if( $response === false ){
@ -104,7 +90,7 @@
} }
/* [6] Decrement cyclic-hash so request has ran successfully /* [5] Decrement cyclic-hash so request has ran successfully
=========================================================*/ =========================================================*/
/* (1) Decrement the hash */ /* (1) Decrement the hash */
$decr = syscall(SOURCE_DIR.'/lib/cyclic-hash/decr'); $decr = syscall(SOURCE_DIR.'/lib/cyclic-hash/decr');
@ -119,7 +105,7 @@
/* [6] Response management /* [5] Response management
=========================================================*/ =========================================================*/
/* (1) Writes request to temporary pipe */ /* (1) Writes request to temporary pipe */
file_put_contents(TMP_DIR.'/api.response', $response); file_put_contents(TMP_DIR.'/api.response', $response);