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

发布于 2024-12-20 07:16:48 字数 1542 浏览 0 评论 0原文

我正在尝试使用名为 BulkLoadContacts 的函数将数据文本文件上传到肥皂服务器。 值

该请求需要一个名为base64Binary

我正在创建一个文件,然后查询我的数据库,写入该文件,然后连接到他们的肥皂服务器,然后发送我的请求。

这是我的代码的片段:

    $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);
}

这是文档中的代码示例:

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

有什么想法如何在 PHP 中执行此操作吗?

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?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

不交电费瞎发啥光 2024-12-27 07:16:48

也许是这样的:

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

在 param 数组中:

'ImportFileStream' => $B64File

也许 PHP 客户端 SOAP 引擎会自动编码为 B64。如果是这种情况,请注释 $B64File = base64_encode($rawFile) 并发送 $rawFile

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.

埋情葬爱 2024-12-27 07:16:48

您无需将数据写入文件 - 只需直接传递它

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

foreach ($list as $l){
    $data = $l['email'] . "|" . $l['First_Name'] . "|" . $l['Last_Name'];
}
$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' => $data
    );

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

如果 SOAP 客户端不会自动将数据编码为 base64,您还需要添加以下内容:

$data = base4_encode($data);

You have no need to write your data to file - just pass it directly

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

foreach ($list as $l){
    $data = $l['email'] . "|" . $l['First_Name'] . "|" . $l['Last_Name'];
}
$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' => $data
    );

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

If SOAP client does not encodes data into base64 automatically, you need to also add this:

$data = base4_encode($data);
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文