Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 3 of 3

Thread: xml base64 php

  1. #1
    naf
    naf is offline
    New to the CF scene
    Join Date
    Jul 2008
    Posts
    2
    Thanks
    0
    Thanked 0 Times in 0 Posts

    xml base64 php

    hi..

    just joined . hi to everyone.

    I am trying to setup a xml for a friend of mine.. the source is a remote http server ...and you can send differnt api request to it and you recieve a responce depending on the request.

    In the api documentation it says the userid and login id must be base 64 encoded..The api request query i send to the remote server I encode the userid and login id.

    I am trying to echo the responce and all get is encoded message.I am been trying to figure out what i need to do to encode it.i tried echo base64_decode($str); but all i get is blank page ..if i do just echo $responce then i get a responce but is un readable.

    here is the code ii am trying to use.i am usng php 5

    PHP Code:
    <?php
    $service_url 
    "https://remote.server.com"?>
    <?php
    $xml 
    '<apiRequest xmlns="API_Request_ProductDetails"> <header> <apiVersion>1</apiVersion> <userID>base64 encoded</userID> <loginGUID>base64 encoded</loginGUID> </header> <request> <searchRequest> <itemcode>item no1</itemcode> </searchRequest> </request> </apiRequest>';?> 


    <?php
    // set curl header options
    $curl_header "POST “.$service_url.” HTTP/1.0 \r\n";
    $curl_header .= "MIME-Version: 1.0 \r\n";
    $curl_header .= "Content-type: application/PTI26 \r\n";
    $curl_header .= "Content-length: ".strlen($xml)." \r\n";
    $curl_header .= "Content-transfer-encoding: text \r\n";
    $curl_header .= "Request-number: 1 \r\n";
    $curl_header .= "Document-type: Request \r\n";
    $curl_header .= "Interface-Version: Test 1.4 \r\n";
    $curl_header .= "Connection: close \r\n\r\n";
    $curl_header .= $xml;// add xml to header
    $curl curl_init();// create curl handler
    // set curl options
    curl_setopt($curlCURLOPT_URL$service_url);
    curl_setopt($curlCURLOPT_RETURNTRANSFER1);
    curl_setopt($curlCURLOPT_TIMEOUT30);
    curl_setopt($curlCURLOPT_CUSTOMREQUEST$curl_header);
    curl_setopt($curlCURLOPT_SSL_VERIFYPEER0);
    curl_setopt($curlCURLOPT_SSL_VERIFYHOST0);
    $response curl_exec($curl);// execute the curl request
    if(curl_errno($curl)){// check for error in processing curl request
    exit;
    }
    curl_close($curl);// close the curl connection    
    ?>
       
    <?php 
      

    //process the returned ****ty xml  
    echo $response;

    //print $response;
    //$str = $response;
    //echo base64_decode($str);

    ?>

    i am still learning php. if i have messed up on something do let me know.
    kind regards
    Last edited by naf; 07-06-2008 at 12:43 AM.

  • #2
    Senior Coder shyam's Avatar
    Join Date
    Jul 2005
    Posts
    1,563
    Thanks
    2
    Thanked 163 Times in 160 Posts
    have you tried sending a normal post request instead of a custom request

    PHP Code:
    $curl_header_arr = array(
    "MIME-Version: 1.0 \r\n",
    "Content-type: application/PTI26 \r\n",
    "Content-transfer-encoding: text \r\n",
    "Request-number: 1 \r\n",
    "Document-type: Request \r\n",
    "Interface-Version: Test 1.4 \r\n",
    "Connection: close \r\n\r\n"
    );
    $curl_header .= $xml;// add xml to header
    $curl curl_init();// create curl handler
    // set curl options
    curl_setopt($curlCURLOPT_URL$service_url);
    curl_setopt($curlCURLOPT_RETURNTRANSFER1);
    curl_setopt($curlCURLOPT_TIMEOUT30);
    curl_setopt($curlCURLOPT_HEADERtrue);
    curl_setopt($curlCURLOPT_HTTPHEADER$curl_header_arr);
    curl_setopt($curlCURLOPT_SSL_VERIFYPEER0);
    curl_setopt($curlCURLOPT_SSL_VERIFYHOST0);
    curl_setopt($curlCURLOPT_POSTtrue);
    curl_setopt($curlCURLOPT_POSTFIELDS$xml);
    $response curl_exec($curl);// execute the curl request 
    You never have to change anything you got up in the middle of the night to write. -- Saul Bellow

  • #3
    naf
    naf is offline
    New to the CF scene
    Join Date
    Jul 2008
    Posts
    2
    Thanks
    0
    Thanked 0 Times in 0 Posts
    thanks for replying.. i get a this error message if i try normal post request

    " Blank xml document or invalid xml structure ".

    If i try my orignal method.i do get a response from the remote server but it is all encoded..looking at the view source this is what i see.i am pasting just a part of it..

    Code:
        </element>
      </attributes>
      <specification>
        <spec_element>
          <spec_title>S2V5Ym9hcmQ=</spec_title>
          <spec_description>TnVtYmVyIG9mIEtleXM=</spec_description>
          <spec_value></spec_value>
        </spec_element>
    
        <spec_element>
          <spec_title>S2V5Ym9hcmQ=</spec_title>
          <spec_description>TnVtYmVyIG9mIEhvdGtleXM=</spec_description>
          <spec_value></spec_value>
        </spec_element>
        <spec_element>
          <spec_title>S2V5Ym9hcmQ=</spec_title>
    
          <spec_description>SW50ZXJuZXQgS2V5</spec_description>
          <spec_value></spec_value>
        </spec_element>
        <spec_element>
          <spec_title>S2V5Ym9hcmQ=</spec_title>
          <spec_description>U2NyZWVuIExvY2sgS2V5</spec_description>


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •