在没有curl或wget的bash中进行SOAP调用

在没有curl或wget的bash中进行SOAP调用,bash,soap,Bash,Soap,我试图编写一个bash脚本来执行SOAP请求(并获取响应)。我可以用它 result=$(wget ${url} --post-data="${data}" --header='Content-Type: text/xml;charset=UTF-8'--timeout=${timeout} -qO- --delete-after) 或 其中,“data”是XML负载 但是,我需要从中执行脚本的服务器没有curl或wget,并且可能没有任何其他此类扩展特性 那么,有没有一种不用它们就能实现这一

我试图编写一个bash脚本来执行SOAP请求(并获取响应)。我可以用它

result=$(wget ${url} --post-data="${data}" --header='Content-Type: text/xml;charset=UTF-8'--timeout=${timeout} -qO- --delete-after)

其中,“data”是XML负载

但是,我需要从中执行脚本的服务器没有curl或wget,并且可能没有任何其他此类扩展特性

那么,有没有一种不用它们就能实现这一目标的方法呢? 一个相关的StackExtenge问题表明这是可能的,尽管他们的要求略有不同。

谢谢

编辑: 在Nic3500的评论之后,我花了一整天的时间阅读nc/netcat,努力寻找我需要的文档。但我已将其发送至以下地址:

POST <remote_URI> HTTP/1.1\r\n
User-Agent: Wget/1.14 (linux-gnu)\r\n
Accept: */*\r\n
Host: <IP Address>\r\n
Connection: Keep-Alive\r\n
Content-Type: text/xml;charset=UTF-8--timeout=10\r\n
Content-Length: <Content Length>\r\n
<?xml version="1.0" encoding="UTF-8"?>
<SOAP-ENV:Envelope xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/" xmlns:ns1="Core" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:SOAP-ENC="http://schemas.xmlsoap.org/soap/encoding/" SOAP-ENV:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/">
  <SOAP-ENV:Body>
    <ns1:Dispatch>
      <param0 xsi:type="xsd:string">some data</param0>
      [more params here]
      <param21 xsi:type="xsd:int">1</param21>
    </ns1:Dispatch>
  </SOAP-ENV:Body>
</SOAP-ENV:Envelope>
POST HTTP/1.1\r\n
用户代理:Wget/1.14(linux gnu)\r\n
接受:*/*\r\n
主机:\r\n
连接:保持活动状态\r\n
内容类型:text/xml;字符集=UTF-8--超时=10\r\n
内容长度:\r\n
一些数据
[这里有更多参数]
1.
使用

echo${head}nc 80
现在,据我所知,它精确地匹配了wget方法发送的内容(它可以工作,只是不能从我需要的服务器执行),这是基于获取wget方法以转储它发送的数据。
然而,很明显有些地方不太对劲,因为我得到的只是一个400个错误的请求。

因此,事实证明我对编辑的尝试并不遥远,只需要在echo命令上打开-e开关:

POST <remote_URI> HTTP/1.1\r\n
User-Agent: Wget/1.14 (linux-gnu)\r\n
Accept: */*\r\n
Host: <IP Address>\r\n
Connection: Keep-Alive\r\n
Content-Type: text/xml;charset=UTF-8--timeout=10\r\n
Content-Length: <Content Length>\r\n
<?xml version="1.0" encoding="UTF-8"?>
<SOAP-ENV:Envelope xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/" xmlns:ns1="Core" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:SOAP-ENC="http://schemas.xmlsoap.org/soap/encoding/" SOAP-ENV:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/">
  <SOAP-ENV:Body>
    <ns1:Dispatch>
      <param0 xsi:type="xsd:string">some data</param0>
      [more params here]
      <param21 xsi:type="xsd:int">1</param21>
    </ns1:Dispatch>
  </SOAP-ENV:Body>
</SOAP-ENV:Envelope>

解决了我遇到的问题,因为-e告诉echo解释换行符,而我使用nc遇到的所有问题实际上都是由于某些形状或形式的行尾不正确。供参考-如上所示-HTTP数据需要CRLF行结尾。

服务器上是否安装了更多“改进”的脚本语言?i、 perl,python,php。。。?与纯bash相比,它们有更好的扩展,您可以使用。@Nic3500遗憾的是,没有perl-python或php。它们喜欢让您的生活陷入地狱;-)看看这个,也许
netcat
nc
会有帮助。
echo ${head} | nc <IP Address> 80
POST <remote_URI> HTTP/1.1\r\n
User-Agent: Wget/1.14 (linux-gnu)\r\n
Accept: */*\r\n
Host: <IP Address>\r\n
Connection: Keep-Alive\r\n
Content-Type: text/xml;charset=UTF-8--timeout=10\r\n
Content-Length: <Content Length>\r\n
<?xml version="1.0" encoding="UTF-8"?>
<SOAP-ENV:Envelope xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/" xmlns:ns1="Core" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:SOAP-ENC="http://schemas.xmlsoap.org/soap/encoding/" SOAP-ENV:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/">
  <SOAP-ENV:Body>
    <ns1:Dispatch>
      <param0 xsi:type="xsd:string">some data</param0>
      [more params here]
      <param21 xsi:type="xsd:int">1</param21>
    </ns1:Dispatch>
  </SOAP-ENV:Body>
</SOAP-ENV:Envelope>
result=$(echo -e "${data}" | nc -w ${timeout} ${url} 80)