doulai8128 2015-12-01 12:46
浏览 35
已采纳

如何从SOAP响应中删除HTTP标头

I am currently integrating with Kashflow and using SOAP calls to send Customer data to my Kashflow account from my Symfony2 site, and it should return the ID of the new customer - I need this in order to save it in the database at my end.

However, upon return, I get the HTTP header and not just the ID, which means it is not inserting it into the database as it needs to be an integer.

Here is the SOAP response:

HTTP/1.1 200 OK
Content-Type: application/soap+xml; charset=utf-8
Content-Length: length

<?xml version="1.0" encoding="utf-8"?>
<soap12:Envelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:soap12="http://www.w3.org/2003/05/soap-envelope">
  <soap12:Body>
    <InsertCustomerResponse xmlns="KashFlow">
      <InsertCustomerResult>int</InsertCustomerResult>
      <Status>string</Status>
      <StatusDetail>string</StatusDetail>
    </InsertCustomerResponse>
  </soap12:Body>
</soap12:Envelope>

I am trying to retrieve the new ID by using:

return new Response((int)$response->soapBody->InsertCustomerResponse->InsertCustomerResult);

But even though the ID does get returned, it spits out the HTTP header above it. Is there any way of removing this? I have tried using preg_replace like this (where $return is the response from the SOAP call):

preg_replace('/((.*)
)*(\d+)$/','$1',$return);

But it just returns a blank.

Any ideas?

Thanks in advance

  • 写回答

1条回答 默认 最新

  • douzhen9428 2015-12-01 15:14
    关注

    I realised that I have to use getContent() on the return in order to get the data I needed.

    So:

    $response = $response->soapBody->InsertCustomerResponse->InsertCustomerResult;
    
    return $response->getContent();
    

    Which then only gets the data I need, and not the header as well.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 GDI处理通道视频时总是带有白色锯齿
  • ¥20 用雷电模拟器安装百达屋apk一直闪退
  • ¥15 算能科技20240506咨询(拒绝大模型回答)
  • ¥15 自适应 AR 模型 参数估计Matlab程序
  • ¥100 角动量包络面如何用MATLAB绘制
  • ¥15 merge函数占用内存过大
  • ¥15 Revit2020下载问题
  • ¥15 使用EMD去噪处理RML2016数据集时候的原理
  • ¥15 神经网络预测均方误差很小 但是图像上看着差别太大
  • ¥15 单片机无法进入HAL_TIM_PWM_PulseFinishedCallback回调函数