Can a json be sent via SOAP in PHP?

0

My question is Can you send a json for SOAP Native to PHP ?

I present my case I have to do an integration with the Web Service of Correos Express. It turns out that they work with SOAP and json . When I try to send the order it shows the following error in Native

  

Fatal error: SOAP Fault: (faultcode: Sender, faultstring: looks like we got no XML document)

According to what I understand the XML armed is wrong and it is obvious I do not want to send an XML I want to send a json

I tried it with nusoap and the error does not throw it away but if it throws me another error

  

nusoap_client: Error: HTTP Error: no data present after HTTP headers

I no longer know which of the two to use because either of them gives me an error. Although I think the native has an easier solution. (You may be wrong)

If you need to share either integration ( nusoap and native). Let me know and I'll put it.

Thank you very much. Greetings.

    
asked by Nazareno Ciancaglini 14.11.2018 в 14:05
source

2 answers

0

can not, nusoap and native soap apparently send only XML , anyway I started using cURL but I'm having a problem that I can not decipher what it is. I hope you can help me.

I show the case

$header = array();
$header[] = "Content-Type: application/json";
$header[] = "cache-control: no-cache";

$array = json_encode($array);
$curl = curl_init();
curl_setopt($curl, CURLOPT_URL, "https://test.correosexpress.com/wspsc/apiRestGrabacionEnvio/json/grabacionEnvio");
curl_setopt($curl, CURLOPT_HTTPHEADER, $header);
curl_setopt($curl, CURLOPT_USERPWD, "xxxxxx:xxxxx");
curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($curl, CURLOPT_SSL_VERIFYHOST, false);
curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
curl_setopt($curl, CURLOPT_POST, true);
curl_setopt($curl, CURLOPT_POSTFIELDS, $array);

$Response = curl_exec($curl);
$errorNo = curl_errno($curl);

if($errorNo){
  $error = curl_error($curl);
  echo $error;
  return false;
}
$info = curl_getinfo($curl);
var_dump($info);

curl_close($curl);
var_dump($Response);

the $ array is the json that I'm trying to send.

the answer I get is the following

C:\wamp64\www\.......\newPedido.php:98:
array (size=26)
  'url' => string 'https://test.correosexpress.com/wspsc/apiRestGrabacionEnvio/json/grabacionEnvio' (length=79)
  'content_type' => null
  'http_code' => int 200
  'header_size' => int 184
  'request_size' => int 258
  'filetime' => int -1
  'ssl_verify_result' => int 19
  'redirect_count' => int 0
  'total_time' => float 30.311
  'namelookup_time' => float 0.125
  'connect_time' => float 0.141
  'pretransfer_time' => float 0.203
  'size_upload' => float 1132
  'size_download' => float 0
  'speed_download' => float 0
  'speed_upload' => float 37
  'download_content_length' => float -1
  'upload_content_length' => float 1132
  'starttransfer_time' => float 0.234
  'redirect_time' => float 0
  'redirect_url' => string '' (length=0)
  'primary_ip' => string 'xxx.xxx.xxx.xxx' (length=14)
  'certinfo' => 
    array (size=0)
      empty
  'primary_port' => int 443
  'local_ip' => string 'xxx.xxx.xxx.xxx' (length=13)
  'local_port' => int 54054
C:\wamp64\www\......\newPedido.php:101:string '' (length=0)

I hope that with that is enough information for an answer. Thank you very much.

    
answered by 20.11.2018 в 12:31
-1

I had a similar problem and I broke my head, in the end I found the solution here: Arne Kröger's Blog and consists of removing all characters (including line breaks, blank spaces) after ?>

As it says there is a simple solution, but I do not know if it will be your case.

Greetings.

    
answered by 14.11.2018 в 14:40