problem with integration with affinityassistance (curl + php + xml)

1

Well I'm with the curl up and running. I'm trying to integrate with the site: link method getplanos.

I send the xml via curl and returns that the parameters were not informed

Name: GetPlanos (available)

Purpose: To return all available plans.

Request Parameters: Login, Password

Response Parameters: Plan Code, Plan Name

example: link

$input_xml="<?xml version='1.0' encoding='UTF-8' ?> 
<requisicao>
    <login>xml28</login>
    <senha>15028</senha>

</requisicao>";

$url = 'https://www.affinityassistencia.com.br/ws/getPlanosLista/';

  //setting the curl parameters.
    $ch = curl_init();
    curl_setopt($ch, CURLOPT_URL, $url);
// Following line is compulsary to add as it is:
    curl_setopt($ch, CURLOPT_HTTPHEADER,
            array('Content-type: application/xml',
                'Content-length: '. strlen($input_xml)) );

    curl_setopt($ch, CURLOPT_POSTFIELDS,
                 $input_xml);
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
    curl_setopt($ch, CURLOPT_USERPWD, "xml28:15028");
    curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 300);
    $data = curl_exec($ch);
    curl_close($ch);


    //convert the XML result into array
//        $array_data = json_decode(json_encode(simplexml_load_string($data)), true);

    print_r('<pre>');
    print_r($data);
    print_r('</pre>');

And then does anyone have any suggestions? Att Gustavo

    
asked by anonymous 23.03.2017 / 16:15

1 answer

2

You have several errors in the code, but I believe it must have been your attempts to find a fix . Your question is very vague, with no exact documentation, but let's go in parts, as Jack said.

TL; DR:

Make a GET using the mensagem parameter, ie:

https://www.affinityassistencia.com.br/ws/getPlanosLista/?mensagem='.urlencode($input_xml)

Using CURLOPT_POSTFIELDS you will do a POST (and not a GET ). But you say you want to use the GetPlans endpoint, if the name has GET, why are you doing a POST?!

  • Use GET .
    • Remove% with%.
    • Remove the header from CURLOPT_POSTFIELDS .
  • Now we need to know what because of Content-length , this is done to login using HTTP Authentication , that is those login / password fields that appear within an alert, probably already saw some there . : P

  • Remove% with%.
  • We have a missing information. What is the name of the parameter to be sent, example CURLOPT_USERPWD , we have y but we do not have x .

    Let's take a look at the submitted page:

  • Use CURLOPT_USERPWD to send XML, while site.com?x=y changes every session, so it does not seem to be important .
  • At the end:

    // Sua chave:
    $parametrosURL['chave'] = '0';
    
    // Sua mensagem:
    $parametrosURL['mensagem'] = "<?xml version='1.0' encoding='UTF-8' ?> 
    <requisicao>
        <login>xml28</login>
        <senha>15028</senha>
    </requisicao>";
    
    $parametrosURL = http_build_query($parametrosURL);
    
    $url = 'https://www.affinityassistencia.com.br/ws/getPlanosLista/?'.$parametrosURL;
    
    $ch = curl_init($url);
    curl_setopt($ch, CURLOPT_HTTPHEADER, ['Content-type: application/xml']);
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
    curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 300);
    $data = curl_exec($ch);
    curl_close($ch);
    
    print_r('<pre>');
    print_r($data);
    print_r('</pre>');
    

    If the key is not important, you can use the example mentioned above:

    $mensagem = "<?xml version='1.0' encoding='UTF-8' ?> 
        <requisicao>
            <login>xml28</login>
            <senha>15028</senha>
        </requisicao>";
    
    $url = 'https://www.affinityassistencia.com.br/ws/getPlanosLista/?mensagem='.urlencode($mensagem);
    
        
    23.03.2017 / 17:49