PHP - Sending Xml To Another Url Using Php (curl)
I'm trying to make this code send some simple XML to another URL using cURL but it keeps giving me "Bad Request (Invalid Number)".
Can anyone see anything obviously wrong with this code that might cause this error? Personally (and I am a newbie), I don't see any line in the code where the actual XML (i.e. $xml) is sent to other URL. Could that be the problem? If I'm simply missing it, can someone explain to me where this code takes the $xml variable and sends it to the other URL. It just seems to me like the $xml variable is given some data and then nothing is done with that variable. Anyone? Code: [Select] <?php $companyKey = '310846'; $server = 'http://67.202.202.153'; $xml = '<?xml version="1.0" encoding="utf-8"?>' . '<LeadImportDatagram>'. '<CompanyKey>' . $companyKey . '</CompanyKey>' . '<NotificationEmailTo>joeschmoe@gmail.com</NotificationEmailTo>' . '<LeadInfo>'; '<City>Osweeego</City>'; '</LeadInfo>'; '</LeadImportDatagram>'; if(substr($server, 0, 4) != 'http') $server = 'http://' . $server; if(substr($server, -1) == '/') $server = rtrim($server, '/'); $curlConfig = array( CURLOPT_POST => true, CURLOPT_RETURNTRANSFER => true ); $curl = curl_init($server . '/xml/importlead.asp'); curl_setopt_array($curl, $curlConfig); $responseText = curl_exec($curl); $httpCode = curl_getinfo($curl, CURLINFO_HTTP_CODE); if($httpCode !== 200) { echo 'Error sending XML: ' . $responseText; exit(0); } header('Location: thanks.php'); exit(0); ?> Similar TutorialsI've looked at various cURL tutorials and the PHP manual, but I don't see what I'm doing wrong here. My goal is to be able to send data to test.php and then have that page run a MySQL query to insert the TITLE and MESSAGE into the database. Any comments? :/ post.php <?php if(isset($_GET['title']) && isset($_GET['message']) && isset($_GET['times'])) { $array = array('title' => urlencode($_GET['title']), 'message' => urlencode($_GET['message'])); foreach($array as $key => $value) { $fields = $key.'='. $value .'&'; } rtrims($felds); //set our init handle $curl_init = curl_init(); //set our URL curl_setopt($curl_init, CURLOPT_URL, 'some url'); //set the number of fields we're sending curl_setopt($curl_init ,CURLOPT_POST, count($array)); for($i = 0; $i < $_GET['times']; $i++) { //send the POST data curl_setopt($curl_init, CURLOPT_POSTFIELDS, $fields); curl_exec($curl_init); echo 'post #'.$i. ' sent<br/>'; } //complete echo '<b>COMPLETE</b>'; //close session curl_close($curl_init); } else { ?> <form action="post.php" method="GET"> <table> <tr><td>Title</td><td><input type="text" name="title" maxlength="30"></td></tr> <tr><td>Content</td><td><textarea name="message" rows="20" cols="45" maxlength="2000"></textarea></td></tr> <tr><td>Process Amount</td><td><input type="text" name="times" size="5" maxlength="3"></td></tr> <tr><td>START</td><td><input type="submit" value="Initiate Posting"></td></tr> </table> </form> <?php } ?> test.php <?php mysql_connect('host', 'user', 'pass'); mysql_select_db('somedb'); if($_POST['title'] && $_POST['message']) { mysql_insert("INSERT INTO tests VALUES (null, '{$_POST['title']}', '{$_POST['message']}')"); } echo '<hr><br/>'; //query $query = mysql_query("SELECT * FROM tests ORDER BY id DESC"); while($row = mysql_fetch_assoc($query)) { echo $row['id'].'TITLE: '. $row['title'] .'<br/>MESSAGE: '. $row['message'] .'<br/><br/>'; } ?> when I send a post variable to another page for processing using cURL and then I echo the variable I am getting extra slashes and periods this is where I set the fields to send. Code: [Select] curl_setopt($ch, CURLOPT_POSTFIELDS,"name='. $name .'&email='. $email .'&serial='. $serialnumber .'"); this is what happens when I echo $serial on the processing page. Code: [Select] \'. SLNM7IV6ZM98YJRXO8D5 .\' it should look like Code: [Select] SLNM7IV6ZM98YJRXO8D5 good day dear community, i am workin on a Curl loop to fetch multiple pages: i have some examples - and a question: Example: If we want to get information from 3 sites with CURL we can do it like so: $list[1] = "http://www.example1.com"; $list[2] = "ftp://example.com"; $list[3] = "http://www.example2.com"; After creating the list of links we should initialize the cURL multi handle and adding the cURL handles. $curlHandle = curl_multi_init(); for ($i = 1;$i <= 3; $i++) $curl[$i] = addHandle($curlHandle,$list[$i]); Now we should execute the cURL multi handle retrive the content from the sub handles that we added to the cURL multi handle. ExecHandle($curlHandle); for ($i = 1;$i <= 3; $i++) { $text[$i] = curl_multi_getcontent ($curl[$i]); echo $text[$i]; } In the end we should release the handles from the cURL multi handle by calling curl_multi_remove_handle and close the cURL multi handle! If we want to another Fetch of sites with cURL-Multi - since this is the most pretty way to do it! Well I am not sure bout the string concatenation. How to do it - Note I want to fetch several hundred pages: see the some details for this target-server sites - /(I have to create a loop over several hundred sites). * siteone.example/?show_subsite=9009 * siteone.example/?show_subsite=9742 * siteone.example/?show_subsite=9871 .... and so on and so forth Question: How to appy this loop into the array of the curl-multi? <?php /************************************\ * Multi interface in PHP with curl * * Requires PHP 5.0, Apache 2.0 and * * Curl * ************************************* * Writen By Cyborg 19671897 * * Bugfixed by Jeremy Ellman * \***********************************/ $urls = array( "siteone", "sitetwo", "sitethree" ); $mh = curl_multi_init(); foreach ($urls as $i => $url) { $conn[$i]=curl_init($url); curl_setopt($conn[$i],CURLOPT_RETURNTRANSFER,1);//return data as string curl_setopt($conn[$i],CURLOPT_FOLLOWLOCATION,1);//follow redirects curl_setopt($conn[$i],CURLOPT_MAXREDIRS,2);//maximum redirects curl_setopt($conn[$i],CURLOPT_CONNECTTIMEOUT,10);//timeout curl_multi_add_handle ($mh,$conn[$i]); } do { $n=curl_multi_exec($mh,$active); } while ($active); foreach ($urls as $i => $url) { $res[$i]=curl_multi_getcontent($conn[$i]); curl_multi_remove_handle($mh,$conn[$i]); curl_close($conn[$i]); } curl_multi_close($mh); print_r($res); ?> I look forward to your ideas. From our website we are connecting to GMAIL to send our emails through SMTP. For some reason it is not sending the emails to the CC or BCC email address event though GMAIL shows it was included in the email. Am I missing something in the below code? Code: [Select] $currentTime = time(); $emailTo = "redbrad0@domain.com"; $emailCC = "brad@domain.com"; $emailBCC = "events@domain.com"; $emailSubject = "TEST Email at (" . $currentTime . ")"; $emailBody = "This is the body of the email"; $headers = array(); if (!empty($emailTo)) $headers['TO'] = $emailTo; if (!empty($emailCC)) $headers['CC'] = $emailCC; if (!empty($emailBCC)) $headers['BCC'] = $emailBCC; if (!empty($emailSubject)) $headers['Subject'] = $emailSubject; $headers['From'] = "events@domain.com"; $mime = new Mail_mime("\n"); $mime->setTXTBody($emailBody); $body = $mime->get(); $headers = $mime->headers($headers); $mail = Mail::factory('smtp', array ('host' => 'ssl://smtp.gmail.com', 'auth' => true, 'port' => 465, 'username' => 'events@domain.com', 'password' => 'thepasswordhere')); try { $result = $mail->send($emailTo, $headers, $emailBody); } catch (TixException $ex) { echo "<font color=red>Error:" . $ex->getCode() . "</font><br>"; } echo "Emailed at (" . $currentTime . ")<br>"; die; I am trying to send the following curl command using PHP but I have so far been unsuccessful, any help would be appreciated :-) curl -u 1fd7b89be6f3533d7:X -H 'Content-Type:application/xml' -d '<message><body>Test using the API</body></message>' http://someurl.com The purpose of this script is to automatically send a message to a campfire chatroom for a PHPUnit script using Selenium What exactly is cURL? What are alternatives to it? I am reading some code for submitting payment info to a Payment Gateway and trying to understand how cURL plays into this?! Thanks, Debbie I am using the following code. Code: [Select] $ch = curl_init(); curl_setopt($ch, CURLOPT_URL, $url); curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false); $response = curl_exec($ch); curl_close($ch); I was given a .cer file should I set CURLOPT_SSL_VERIFYPEER to TRUE and set the path to the .cer file? Any help would be awesome. Thanks Can anyone help me with setting the content-type with CURL/PHP for file uploads? I've tried all of the common methods, and nothing seems to be working. For example Code: [Select] curl_setopt($session, CURLOPT_HTTPHEADER,array ( "Content-Type: image/gif", )); Thanks! I want to grab the title of a cl page using curl, can anyone help me with this?
I have the urls stored in a table I just need can't get it to read the title of the post in CL, let me know if you can help.
how to pass data on other domain in PHp or curl ?? and also how to get data on other domain ?? if anyone knows how to do it please attach code hello i`m new here . i need someone to build a php script with CURL and <iframe> i can pay for the script PM back or email me here icemerc@yahoo.com can someone help me create a cURL for this? i think its a get method, right? Access it including the GET parameters and make sure that settings are also follows. Dispatcher URL: http://website.net/gw/dispatcher.woof GET Parameters: RRN is the random reference number SRC is the access code (i.e 2336) DST is the recipient of the message (i.e. 639209547958) MSG is the actual reply message up to 420 characters, including non printable characters. KYWRD is the primary keyword (i.e. hello) need help. thanks.. this is my current code <?php //getting the value of RRN $rrn=urlencode($_GET['rrn']); //getting the value of MSG $msg=urlencode($_GET['msg']); //getting the value of DST $dst=urlencode($_GET['dst']); //getting the value of SRC $src=urlencode($_GET['src']); //setting up the value of KYWRD $kywrd = urlencode('KEYWORD'); //assuming that the dst here is 2336 $aw = "haha"; $str= "?src=".$dst."&dst=".$src."&msg=".$aw."&rrn=".$rrn."&kywrd=".$kywrd; print $str; $ch=curl_init(); curl_setopt($ch,CURLOPT_URL,' http://www.website.net/gw/dispatcher.woof'.$str); curl_exec($ch); curl_close($ch); ?> Is this correct? Thanks Hi. I am fairly new with cURL.
I have a URL like example.com/index.php?something=value&somethingtwo=valuetwo
How can I get those values and print them out?
I've got this code, but have no idea what to do next, please help guys!
<?php function get($url, $params=array()) { $url = $url.'?'.http_build_query($params, '', '&'); $ch = curl_init(); curl_setopt($ch, CURLOPT_URL, $url); curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 10); curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false); $response = curl_exec($ch); curl_close($ch); return $response; } // Sample call echo get('https://www.example.com/index.php', array('something'=>'value', 'somethingtwo'=>'valuetwo')); ?> Hey guys I'm trying to log into this website using curl. I did some reading and think I'm pretty close but I cant get the login working It just returns nothing. there is a commented out part which is the page i'm trying to load after I successfully login.
<? $username = 'xxxxxxx'; $password = 'xxxxxxx'; $postinfo = "username=".$username."&password=".$password; $cookie="cookie.txt"; $ch = curl_init(); // extra headers $headers[] = "Accept: */*"; $headers[] = "Connection: Keep-Alive"; curl_setopt($ch, CURLOPT_HTTPHEADER, $headers); curl_setopt($ch, CURLOPT_HEADER, 0); curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 0); curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false); curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1); curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "POST"); curl_setopt($ch, CURLOPT_URL, 'https://weblogin.asu.edu/cas/login'); curl_setopt($ch, CURLOPT_POST, 1); curl_setopt($ch, CURLOPT_POSTFIELDS, $postinfo); curl_setopt($ch, CURLOPT_USERAGENT, "Mozilla/4.0 (compatible; MSIE 5.01; Windows NT 5.0)"); curl_setopt($ch, CURLOPT_COOKIESESSION, true); curl_setopt($ch, CURLOPT_COOKIEJAR, $cookie); $data = curl_exec($ch); if (curl_error($ch)) { echo curl_error($ch); } echo $data; curl_close($ch); // //page with the content I want to grab after logging in (test after login works) // curl_setopt($ch, CURLOPT_URL, "https://webapp4.asu.edu/myasu/"); // curl_setopt($ch, CURLOPT_POST, false); // $data = curl_exec($ch); // if (curl_error($ch)) { // echo curl_error($ch); // } ?>I'm not sure but I think im maybe missing some other parts the form needs? How do I see exactly what I need to send? Hey guys I need help with curl php . I cannot get info from other website. I have been trying to get single post but I'm gettig the whole page or more than one post. I get tutorial from youtube, but for some reason its not working. Does anyone can help me with simple example ? code prehaps? hy all long time no see recently i did find this problem i'm trying to login to a webpage with curl ,but without success ,ofcourse the basic posting is not the problem xD but the page have a hidden field (for security) so everytime you load the page it changes so post wont work if you first use get to take the page and extract the hash from it. the page contains something like input type= hidden value=A RANDOM VALUE THAT CHANGES EVERYTIME without that value passed to post it wont login. anyone knows how can i pass it so the post will be valid? thank you I have a large list of websites that have allowed me to submit my website and description every 24 hours to there sites. I'm really getting tired of sitting by my computer and submitting the information to every site manually. I never understood curl and php dom stuff. does anyone have a easy code where I can post a pre scripted text of my information into three boxes and it auto submits every 24 hours to the websites? The boxes look like this Code: [Select] <input maxlength="255" value="http://" name="sPlugurl" size="20" style="font-family: Verdana; color: FE9999; font-size: 10pt; background-color: 656565; font-weight: none; border: 1px solid #0C0C0C" type="text"> <input maxlength="30" value="Sitename" name="sPlugname" size="20" style="font-family: Verdana; color: FE9999; font-size: 10pt; background-color: 656565; font-weight: none; border: 1px solid #0C0C0C" type="text"> <input maxlength="255" value="Description" name="sPlugdescription" size="20" style="font-family: Verdana; color: FE9999; font-size: 10pt; background-color: 656565; font-weight: none; border: 1px solid #0C0C0C" type="text"> <input type="submit" value="Dump" style="background-color: #656565; font-family: Verdana; color: <? echo ;?>; font-size: 10pt; border: 1px solid #0C0C0C"> the php script would auto fill out the value of the first 3 boxes with my info and then the program would submit it to there forum. I looked on google but nothing I found I can figure out? Hi there, I wanted to create files from my phpscript. So I used the most obvious function, fopen(). It didn't work on my server and contacted the administrator, who said fopen() was disabled for security reasons, and that I should use cURL. So I did what everyone would do; I googled it. Found the php.net curl manual, but can't really comprehend what it sais. So I have a few questions: 1) Can you create .php files with cURL? 2) How? 3) How do I then write php-content in the file? Please try to explain rather detailed and simplified, I've never been good at quickly understanding all these things. Thanks a lot! Hello I want download a webpage with curl on my host using php. but when I use curl didn't download this page, if I change curl to file_get_contents and use it download this page. please help me to resolve my problem. URL is : www.ebook33.com CUL code is : function Get($url) { $hCurl = curl_init($url); curl_setopt($hCurl, CURLOPT_RETURNTRANSFER, TRUE); $ret = curl_exec($hCurl); curl_close($hCurl); return ($ret); File get content code is : file_get_contents($url); |