gpt4 book ai didi

c# - 在 PHP 中通过 SOAP 发送 Zip 文件

转载 作者:太空宇宙 更新时间:2023-11-03 10:33:47 25 4
gpt4 key购买 nike

我必须将文件发送到 WSDL,该元素在 WSDL 中描述为:

<s:element minOccurs="0" maxOccurs="1" name="theZipFile" type="s:base64Binary" />

如何使用 SOAP 客户端发送 Zip 文件?我尝试了以下方法:

$client = new SoapClient($url);
$params = array("theZipFile" => "file.zip");
$response = $client->theFunction($params);

但我没有得到预期的响应。我尝试使用 .Net 和 C# 以及以下代码:

string filename = "file.zip";
FileInfo fi = new FileInfo(filename);
long numBytes = fi.Length;
FileStream fs = new FileStream(filename, FileMode.Open, FileAccess.Read);
BinaryReader br = new BinaryReader(fs);
byte[] data = br.ReadBytes((int)numBytes);
br.Close();
fs.Close();

XElement response = client.theFunction(data);

而且它没有任何问题。

谢谢!

最佳答案

由于某些奇怪的原因,SoapClient 没有发送正确的 XML,显然是定义有问题。

改为使用 CURL。

function SOAPRawRequest($url, $postString, &$error) {
$soap_do = curl_init();
curl_setopt($soap_do, CURLOPT_URL, $url );
curl_setopt($soap_do, CURLOPT_CONNECTTIMEOUT, 10);
curl_setopt($soap_do, CURLOPT_TIMEOUT, 10);
curl_setopt($soap_do, CURLOPT_RETURNTRANSFER, true );
curl_setopt($soap_do, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($soap_do, CURLOPT_SSL_VERIFYHOST, false);
curl_setopt($soap_do, CURLOPT_POST, true );
curl_setopt($soap_do, CURLOPT_POSTFIELDS, $postString);
curl_setopt($soap_do, CURLOPT_HTTPHEADER,
array('Content-Type: text/xml; charset=utf-8',
"Accept: text/xml",
"Cache-Control: no-cache",
"Pragma: no-cache",
"SOAPAction: \"http://tempuri.org/theFunction\"",
'Content-Length: '.strlen($postString)
));

$result = curl_exec($soap_do);
$error = curl_error($soap_do);

return $result;
}

还将 $params = array("theZipFile"=> "file.zip"); 更改为:

$content = file_get_contents("file.zip");
$content64 = base64_encode($content);

关于c# - 在 PHP 中通过 SOAP 发送 Zip 文件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28733428/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com