将特定数据类型发送到 SOAP 服务器 - base64binary
我正在尝试使用名为 BulkLoadContacts 的函数将数据文本文件上传到肥皂服务器。 值
该请求需要一个名为
的
我正在创建一个文件,然后查询我的数据库,写入该文件,然后连接到他们的肥皂服务器,然后发送我的请求。
这是我的代码的片段:
$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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
也许是这样的:
在 param 数组中:
也许 PHP 客户端 SOAP 引擎会自动编码为 B64。如果是这种情况,请注释
$B64File = base64_encode($rawFile)
并发送$rawFile
。Maybe something like this:
In the param array:
Maybe PHP client SOAP engine encodes to B64 automatically. If this is the case, comment
$B64File = base64_encode($rawFile)
and send$rawFile
instead.您无需将数据写入文件 - 只需直接传递它
如果 SOAP 客户端不会自动将数据编码为 base64,您还需要添加以下内容:
You have no need to write your data to file - just pass it directly
If SOAP client does not encodes data into base64 automatically, you need to also add this: