ChatGPT解决这个技术问题 Extra ChatGPT

如何从命令行调用 SOAP wsdl Web 服务

我需要对 https://sandbox.mediamind.com/Eyeblaster.MediaMind.API/V2/AuthenticationService.svc?wsdl 进行 SOAP Web 服务调用,并在传递参数时使用 ClientLogin 操作:ApplicationKey、Password 和 UserName。响应是 UserSecurityToken。它们都是字符串。

这是完全解释我想要做什么的链接:https://sandbox.mediamind.com/Eyeblaster.MediaMind.API.Doc/?v=3

如何在命令行上执行此操作? (Windows 和/或 Linux 会有所帮助)


D
DeegC

它是一个标准的普通 SOAP Web 服务。 SSH 在这里无关。我只是用 (单行)调用它:

$ curl -X POST -H "Content-Type: text/xml" \
    -H 'SOAPAction: "http://api.eyeblaster.com/IAuthenticationService/ClientLogin"' \
    --data-binary @request.xml \
    https://sandbox.mediamind.com/Eyeblaster.MediaMind.API/V2/AuthenticationService.svc

其中 request.xml 文件具有以下内容:

<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:api="http://api.eyeblaster.com/">
           <soapenv:Header/>
           <soapenv:Body>
              <api:ClientLogin>
                 <api:username>user</api:username>
                 <api:password>password</api:password>
                 <api:applicationKey>key</api:applicationKey>
              </api:ClientLogin>
          </soapenv:Body>
</soapenv:Envelope>

我得到了这个漂亮的 500:

<?xml version="1.0"?>
<s:Envelope xmlns:s="http://schemas.xmlsoap.org/soap/envelope/">
  <s:Body>
    <s:Fault>
      <faultcode>s:Security.Authentication.UserPassIncorrect</faultcode>
      <faultstring xml:lang="en-US">The username, password or application key is incorrect.</faultstring>
    </s:Fault>
  </s:Body>
</s:Envelope>

你试过吗?

Read more


+1 soapui,一个非常有用且免费的工具,用于处理基于肥皂的网络服务。比使用命令行恕我直言要好得多。
您使用的是哪个版本的 curl?我的说“无法解析主机'--data-binary',并且 https 是“不受支持的协议”。
如果我完全按照您的做法进行操作,那么我总是会从 mediamind 收到一条错误消息,提示“发生了意外的内部服务器错误”。有没有什么你没有包括在我应该做的答案中(除了用真实的替换 un/pw/key )?
@Marina:现在我也收到“500 Internal Server Error”。然而,这是一个服务器端错误,而不是我们的 (?),请询问 WS 提供者发生了什么。几天前它还在工作。
感谢您的回答。 request.xml 中缺少 /Envelope,导致服务器响应错误。一旦我补充说它工作正常。也许这就是其他人遇到错误的问题。
l
linuxeasy

在 linux 命令行上,您可以简单地执行:

curl -H "Content-Type: text/xml; charset=utf-8" -H "SOAPAction:"  -d @your_soap_request.xml -X POST https://ws.paymentech.net/PaymentechGateway

b
bmatovu

这是另一个示例 CURL - 银行 swift codes 的 SOAP (WSDL) 请求

要求

curl -X POST http://www.thomas-bayer.com/axis2/services/BLZService \
  -H 'Content-Type: text/xml' \
  -H 'SOAPAction: blz:getBank' \
  -d '
  <soapenv:Envelope 
    xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" 
    xmlns:blz="http://thomas-bayer.com/blz/">
    <soapenv:Header/>
    <soapenv:Body>
      <blz:getBank>
        <blz:blz>10020200</blz:blz>
      </blz:getBank>
    </soapenv:Body>
  </soapenv:Envelope>'

回复

< HTTP/1.1 200 OK
< Server: Apache-Coyote/1.1
< Content-Type: text/xml;charset=UTF-8
< Date: Tue, 26 Mar 2019 08:14:59 GMT
< Content-Length: 395
< 
<?xml version='1.0' encoding='UTF-8'?>
<soapenv:Envelope
  xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/">
  <soapenv:Body>
    <ns1:getBankResponse
      xmlns:ns1="http://thomas-bayer.com/blz/">
      <ns1:details>
        <ns1:bezeichnung>BHF-BANK</ns1:bezeichnung>
        <ns1:bic>BHFBDEFF100</ns1:bic>
        <ns1:ort>Berlin</ns1:ort>
        <ns1:plz>10117</ns1:plz>
      </ns1:details>
    </ns1:getBankResponse>
  </soapenv:Body>
</soapenv:Envelope>

+1 用于指示多个标题行(另一个 -H),并且将所有标题都放在一个位置很整洁。在 SAP 环境中工作。
g
gogasca

使用卷曲:

SOAP_USER='myusername'
PASSWORD='mypassword'
AUTHENTICATION="$SOAP_USER:$PASSWORD"
URL='http://mysoapserver:8080/meeting/aws'
SOAPFILE=getCurrentMeetingStatus.txt
TIMEOUT=5

卷曲请求:

curl --user "${AUTHENTICATION}" --header 'Content-Type: text/xml;charset=UTF-8' --data @"${SOAPFILE}" "${URL}" --connect-timeout $TIMEOUT

我用它来验证响应:

http_code=$(curl --write-out "%{http_code}\n" --silent --user "${AUTHENTICATION}" --header 'Content-Type: text/xml;charset=UTF-8' --data @"${SOAPFILE}" "${URL}" --connect-timeout $TIMEOUT --output /dev/null)
if [[ $http_code -gt 400 ]];  # 400 and 500 Client and Server Error codes http://en.wikipedia.org/wiki/List_of_HTTP_status_codes
then
echo "Error: HTTP response ($http_code) getting URL: $URL"
echo "Please verify parameters/backend. Username: $SOAP_USER Password: $PASSWORD Press any key to continue..."
read entervalue || continue
fi

$USERNAME 解析为我的 linux 用户名,在我的脚本中更改为 $USER
T
Techie
curl --header "Content-Type: text/xml;charset=UTF-8" --header "SOAPAction:ACTION_YOU_WANT_TO_CALL" --data @FILE_NAME URL_OF_THE_SERVICE 

上面的命令对我有帮助

例子

curl --header "Content-Type: text/xml;charset=UTF-8" --header "SOAPAction:urn:GetVehicleLimitedInfo" --data @request.xml http://11.22.33.231:9080/VehicleInfoQueryService.asmx 

More info


J
JamesQMurphy

对于寻找 PowerShell 替代品的 Windows 用户,这里是(使用 POST)。为了便于阅读,我将其分成多行。

$url = 'https://sandbox.mediamind.com/Eyeblaster.MediaMind.API/V2/AuthenticationService.svc'
$headers = @{
    'Content-Type' = 'text/xml';
    'SOAPAction' = 'http://api.eyeblaster.com/IAuthenticationService/ClientLogin'
}
$envelope = @'
    <Envelope xmlns="http://schemas.xmlsoap.org/soap/envelope/">
        <Body>
            <yourEnvelopeContentsHere/>
        </Body>
    </Envelope>
'@     # <--- This line must not be indented

Invoke-WebRequest -Uri $url -Headers $headers -Method POST -Body $envelope

F
Fuzzy Analysis

对于 Windows:

将以下内容另存为 MSFT.vbs:

set SOAPClient = createobject("MSSOAP.SOAPClient")
SOAPClient.mssoapinit "https://sandbox.mediamind.com/Eyeblaster.MediaMind.API/V2/AuthenticationService.svc?wsdl"
WScript.Echo "MSFT = " & SOAPClient.GetQuote("MSFT")

然后从命令提示符运行:

C:\>MSFT.vbs

参考:http://blogs.msdn.com/b/bgroth/archive/2004/10/21/246155.aspx


今年 2004 年的技术至少在 Window 7 上失败了。
A
Aram Paronikyan

对于 Windows,我发现这有效:

Set http = CreateObject("Microsoft.XmlHttp")
http.open "GET", "http://www.mywebservice.com/webmethod.asmx?WSDL", FALSE
http.send ""
WScript.Echo http.responseText

参考:CodeProject


关注公众号,不定期副业成功案例分享
关注公众号

不定期副业成功案例分享

领先一步获取最新的外包任务吗?

立即订阅