doubishi8303 2011-12-08 19:34
浏览 135
已采纳

将特定数据类型发送到SOAP服务器 - base64binary

I am trying to upload a text file of data to a soap server with a function called BulkLoadContacts. The request requires a value called

<ImportFileStream>base64Binary</ImportFileStream>

I am creating a file, then querying my database, writing to the file, then connecting to their soap server, then sending my request.

Here is a snippit of my code:

    $file = 'tempfile.txt';
$handle = fopen($file, 'w') or die ('Cannot open file: ' . $file);

$list = dbExec("select * from listrak_upload");


foreach ($list as $l){

    $data = $l['email'] . "|" . $l['First_Name'] . "|" . $l['Last_Name'];

    fwrite($handle, $data);
}
$ap_param = array( 
    'ListID'    => (integer) 252403,
    'WSImportDirectives'    => array(
        'ImportTypeEnum'        => 'AddSubscribers',
        'ImportProfileTypeEnum' => 'Overwrite',
        'FileName'              => '',
        'HasColumnNames'        => true,
        'FileName'              => $file,
        'FileDelimiter'         => '|',
    ),
    'fileMappings'  => array(
        'WSFileMappings'    => array(
            'FileColumn'            => 0,
            'IsEmailAddressColumn'  => true,
            'AttributeID'           => 'email',
        ),
),
        'ImportFileStream' => $handle
    );

try {
    $return = $soapClient->__soapCall("BulkLoadContacts",array('parameter' => $ap_param));
    var_dump($return);
}
catch(SoapFault $fault){
    var_dump($fault);
}

Here is a code example from the documentation:

Byte[] fileBytes = System.IO.File.ReadAllBytes("C:\\Temp\\ImportFiles\\TestImportFileWithProfile.txt");

Any ideas how to do this in PHP?

  • 写回答

2条回答 默认 最新

  • doutian3010 2011-12-16 11:49
    关注

    Maybe something like this:

    $fileName = "test.txt";
    $rawFile = fread(fopen($fileName, "r"), filesize($fileName));
    $B64File = base64_encode($rawFile)
    

    In the param array:

    'ImportFileStream' => $B64File
    

    Maybe PHP client SOAP engine encodes to B64 automatically. If this is the case, comment $B64File = base64_encode($rawFile) and send $rawFile instead.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥15 用友U8:向一个无法连接的网络尝试了一个套接字操作,如何解决?
  • ¥30 我的代码按理说完成了模型的搭建、训练、验证测试等工作(标签-网络|关键词-变化检测)
  • ¥50 mac mini外接显示器 画质字体模糊
  • ¥15 TLS1.2协议通信解密
  • ¥40 图书信息管理系统程序编写
  • ¥20 Qcustomplot缩小曲线形状问题
  • ¥15 企业资源规划ERP沙盘模拟
  • ¥15 树莓派控制机械臂传输命令报错,显示摄像头不存在
  • ¥15 前端echarts坐标轴问题
  • ¥15 ad5933的I2C