我需要对 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 会有所帮助)
它是一个标准的普通 SOAP Web 服务。 SSH 在这里无关。我只是用 curl (单行)调用它:
$ 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>
你试过soapui吗?
在 linux 命令行上,您可以简单地执行:
curl -H "Content-Type: text/xml; charset=utf-8" -H "SOAPAction:" -d @your_soap_request.xml -X POST https://ws.paymentech.net/PaymentechGateway
这是另一个示例 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>
使用卷曲:
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
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
对于寻找 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
对于 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
对于 Windows,我发现这有效:
Set http = CreateObject("Microsoft.XmlHttp")
http.open "GET", "http://www.mywebservice.com/webmethod.asmx?WSDL", FALSE
http.send ""
WScript.Echo http.responseText
参考:CodeProject
不定期副业成功案例分享