send post include text and image by xmlrpc to wordpress - image

Im looking for a way to send remotely content(text and image ) by xmlrpc to wordpress but i couldn't find yet, im going to sent remotely content (text and image) over 100 post per minute to wordpress, whats the best way to do it? thanks so much

Use XMLRPC. Something like this:
$params = array(0,$username,$password,$content,true);
$request = xmlrpc_encode_request('metaWeblog.newPost',$params);
$ch = curl_init();
curl_setopt($ch, CURLOPT_POSTFIELDS, $request);
curl_setopt($ch, CURLOPT_URL, $rpcurl);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_TIMEOUT, 1);
$results = curl_exec($ch);
curl_close($ch);

Related

Why curl to another server dont work in codeigniter?

I am working on codeigniter and I am doing a POST request curl for another project that is located on another server that is on another network.
This is my code.
controller from my webpage
function submit_form() {
error_log("data: ". $_POST);
$data = $this->input->post('data');
$data = json_decode($data,true);
error_log("data id: ".$data['idParceiro']);
// where are we posting to?
$url = 'http://mywebdomain/ncsync/Sync/getLogin';
$fields = array('idParceiro' => $data['idParceiro']);
// build the urlencoded data
$postvars = http_build_query($fields);
// open connection
$ch = curl_init();
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);
curl_setopt($ch, CURLOPT_AUTOREFERER, 1);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0);
curl_setopt($ch, CURLOPT_HEADER, 0);
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_POST, count($fields));
curl_setopt($ch, CURLOPT_POSTFIELDS, $postvars);
// execute post
$result = curl_exec($ch);
The error_log on the server that receives the post is not being printed, hence I conclude that nothing is coming.
this is my .htaccess in my server that receive the request in folder /application
<IfModule authz_core_module>
Require all denied
</IfModule>
<IfModule !authz_core_module>
Deny from all
</IfModule>
Note: This works on localhost when I am on the same network as the server to which I am requesting.
Can help me?

POST requests require a Content-length header in laravel

$output = Curl::httpGet("https://bhleh.com/emailstorage", "POST", $params);
return $output;
this is in my laravel but when ever i try to run this i get an error saying
411. That’s an error.
POST requests require a Content-length header. That’s all we know.
i tried adding header files in my middle ware folder but nothing seems to work.
i figured out that the Content-length header isn't included in laravel (i think so not so sure) so how would i add it
please note i am very new to laravel
this fix to this is that this i replaced the whole code with this
$data_string = json_encode($params);
$ch = curl_init('https://bhleh.com/emailstorage');
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "POST");
curl_setopt($ch, CURLOPT_POSTFIELDS, $data_string);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_HTTPHEADER, array(
'Content-Type: application/json',
'Content-Length: ' . strlen($data_string))
);
$result = curl_exec($ch);
return $result;
I was facing the same issue but I was not sending CURLOPT_POSTFIELDS as per the API endpoint. I don't need to send any variable but when I send CURLOPT_POSTFIELDS with a blank array it started working.
$data_string = array();
$ch = curl_init('https://bhleh.com/emailstorage');
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "POST");
curl_setopt($ch, CURLOPT_POSTFIELDS, http_build_query($data_string));
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_HTTPHEADER, array(
'Content-Type: application/json'
);
$result = curl_exec($ch);
return $result;

Codeigniter hit an url and get back

I am using codeigniter 3.0 in my webapp. I want to hit an URL then get back to a view. Lets say on clicking a button, I want to hit an API then return back to the same view with success message. Can anyone help?
My API is http://wmlab.in/api/getData.php?username=web
I tried file('http://wmlab.in/api/getData.php?username=web') but it is not working.
use curl to do that and also install curl if your server did not have curl.
url="http://wmlab.in/api/getData.php?username=web";
function getUrlContent($url){
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 5);
curl_setopt($ch, CURLOPT_TIMEOUT, 5);
$data = curl_exec($ch);
echo $httpcode = curl_getinfo($ch, CURLINFO_HTTP_CODE);
curl_close($ch);
return ($httpcode>=200 && $httpcode<300) ? $data : false;
}
$content=getUrlContent($url);
echo $content;
You can use file_get_contents('http://wmlab.in/api/getData.php?username=web') or can use curl;
For Curl use below code:-
$channel = curl_init();
curl_setopt( $channel, CURLOPT_URL, "http://wmlab.in/api/getData.php?username=web" );
curl_setopt( $channel, CURLOPT_RETURNTRANSFER, 1 );
$response= curl_exec ( $channel );
curl_close ( $channel );
// after curl response redirect to othe page
redirect('anypage');
For file get content use below code:-
$response=file_get_contents('http://wmlab.in/api/getData.php?username=web')
// after response redirect to othe page
redirect('anypage');
Hope it will help you.
it should be work
$result=file_get_contents('http://wmlab.in/api/getData.php?username=web');

Square Connect API - image upload - Empty Reply From Server code 52 error

Trying to get square connect API image upload working using PHP.
I used the square connect API guide: docs.connect.squareup.com/api/connect/v1/#post-image
Tried two different ways based on what I found on StackOverflow and Google searching.
Method 1) regular curl request:
https://gist.github.com/delalis/17c3c111e3b42df127ed
Method 2) using CURLFile (php >=5.5 only)
https://gist.github.com/delalis/5c7ecc2aaa024927b360
Both methods gave me this empty reply from server error:
Error: "Empty reply from server" - Code: 52
I am able to connect to square to do other functions no problem, image uploading however is proving to be quite difficult!
Any help would be greatly appreciated.
Here's a working PHP example that I usually share with people:
https://gist.github.com/tdeck/7118c7128a4a2b653d11
<?php
function uploadItemImage($url, $access_token, $image_file) {
$headers = ["Authorization: Bearer $access_token"];
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, ['image_data' => "#$image_file;type=image/jpeg"]);
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
$data = curl_exec($ch);
$return_status = curl_getinfo($ch, CURLINFO_HTTP_CODE);
print "POST to $url with status $return_status\n";
curl_close($ch);
return $data ? json_decode($data) : false;
}
print_r(
uploadItemImage(
'https://connect.squareup.com/v1/me/items/ITEM_ID/image',
'ACCESS_TOKEN',
'IMAGE_FILE.jpg'
)
);
?>

500 Internal Server Error on Payza IPN Handler

I am migrating an app from PayPal to Payza (formerly AlertPay). When I run the code directly from the browser to test the token handling it shows up in the logs and I get a proper response: token=47TXhMVgdPrmV3n5aauIZ5CC0MrytYXWjID81pjVnQsEhkSUklPXT3clXZ4SFUFOL5WqepRUpBz5SKomoyPuDw==& INVALID TOKEN. When I run the full IPN response directly in the browser I get a fail but no visible errors.
But when I generate a transaction or resend an IPN from Payza it is not showing up in the log and I am getting a 500 Internal Server Error. I have turned on allow Query Strings in the CI config file.
class PayzaIPN {
function validate_ipn($payzaIPN ='',$logId = null) {
define("IPN_V2_HANDLER", "https://secure.payza.com/ipn2.ashx");
define("TOKEN_IDENTIFIER", "token=");
$_POST['token'] = '';
$token = urlencode($_POST['token']);
$token = TOKEN_IDENTIFIER.$payzaIPN;
$response = '';
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, IPN_V2_HANDLER);
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_POSTFIELDS, $token);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_HEADER, false);
curl_setopt($ch, CURLOPT_TIMEOUT, 60);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
$response = curl_exec($ch);
curl_close($ch);
if(strlen($response) > 0)

Resources