Post XML file HTTP to an address _php tutorial

Source: Internet
Author: User
Recently did a small task, SMS, MMS, the mass function. The partner provides an interface, we just need to put the content to be sent into an XML, and then HTTP POST to that address on the line. Here is the use of the Curl Library, a simple record of usage.

Below is a small program of bulk SMS, first get the number from an uploaded phone number text, and then get the content to send.

 0) {echo ' problem: '; Switch ($_files[' phone_num ' [' Error ']) {//1 indicates that the file exceeds the size limit in the PHP configuration case 1:echo ' file exceeded max in phi.ini! '; BREAK;//2 indicates that the maximum limit case 2:echo ' file exceeded max_file_size '; BREAK;//3 indicates partial upload case 3:echo ' file only partially Uploade d '; Break;//4 said 4:echo ' no file Upload ' was not uploaded;  Break }exit;} If the file type is non-plain text, the output prompts if ($_files[' phone_num ' [' type ']! = ' Text/plain ') {echo ' problem:file is not plain text '; exit;} Transfer file path, transfer failed, output error $dir = DirName (__file__). ' /upload/'; $filename = $_files[' phone_num ' [' name ']; $savepath = "$dir/$filename"; if (Is_uploaded_file ($_files[' phone_num ' [' tmp_name '])) {$state = Move_uploaded_file ($_files[' phone_num '] [' Tmp_ Name '], $savepath);//If the upload is successful, preview if ($state) {//echo "";} /**if (!move_uploaded_file ($_files[' phone_num ' [' tmp_name '], $savepath)) {echo ' problem could not move file to Destination directory '; exit;} */}else {echo ' problem:p ossible file upload attack File: '; echo $_files[' phone_num ' [' Name '];exit;} $PN = file_get_contents ($savepath); $content = $_post[' content ']; $xml _data = ' 
 
 
   
   
    3100
    
   
    lwxkk
    
   
    1234567
    
   
    106581036177
    
   
    '. $pn. ' 
   
 
 
 
 
 
 
   
  
    '. $content. '
 
   

  
 '; $url = ' http://www.bkjia.com/service/taskSubmit ';//Receive XML address $header = "content-type:text/xml";//define Content-type as XML $ch = Curl_init (); Initialize Curlcurl_setopt ($ch, Curlopt_url, $url);//Set link curl_setopt ($ch, Curlopt_returntransfer, 1);//Set whether to return information Curl_ Setopt ($ch, Curlopt_httpheader, $header);//Set HTTP header curl_setopt ($ch, Curlopt_post, 1);//set to POST mode curl_setopt ($ch, Curlopt_postfields, $xml _data);//post Data $response = curl_exec ($ch);//Receive return information if (Curl_errno ($ch)) {//error message Print Curl_error ($ch);} Curl_close ($ch); Turn off the curl link echo $response;//Display return information?>

MMS Mass is a little more trouble, need to according to the requirements of text, pictures, mms.smil and other files according to the rules named and packaged, but the principle of transmission is the same.

 
 
   
   
    310
    
   
    lwxk
    
   
    123456
    
   
    106581036177
    
   
    '. $pn. ' 
   
 
 
 
 
 
 
   
  
    '. $title. '
  
    
     '. $encoded. ' 
    
 
   

  
 '; $url = ' http://www.bkjia.com/service/taskSubmit ';//Receive XML address $header = "content-type:text/xml";//define Content-type as XML $ch = Curl_init (); Initialize Curlcurl_setopt ($ch, Curlopt_url, $url);//Set link curl_setopt ($ch, Curlopt_returntransfer, 1);//Set whether to return information Curl_ Setopt ($ch, Curlopt_httpheader, $header);//Set HTTP header curl_setopt ($ch, Curlopt_post, 1);//set to POST mode curl_setopt ($ch, Curlopt_postfields, $xml _data);//post Data $response = curl_exec ($ch);//Receive return information if (Curl_errno ($ch)) {//error message Print Curl_error ($ch);} Curl_close ($ch); Turn off the curl link echo $response;//Display return information?>

In fact, it is very simple, is to put the content into an XML string, according to the requirements of base_64 coding, and then post to the address on the line.

http://www.bkjia.com/PHPjc/752471.html www.bkjia.com true http://www.bkjia.com/PHPjc/752471.html techarticle recently did a small task, SMS, MMS, the mass function. The partner provides an interface, we just need to put the content to be sent into an XML, and then HTTP POST to that address on the line. ...

  • Contact Us

    The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

    If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

    A Free Trial That Lets You Build Big!

    Start building with 50+ products and up to 12 months usage for Elastic Compute Service

    • Sales Support

      1 on 1 presale consultation

    • After-Sales Support

      24/7 Technical Support 6 Free Tickets per Quarter Faster Response

    • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.