我的用户名和密码应该放在SOAP api的POST中

I_A*_*ROD 5 api soap r

我把api电话放在一起.在这一点上,我甚至不确定它是否正确.我需要添加我的用户名和密码,但不知道在哪里.任何有关用户名和密码放置的建议都将不胜感激.

api调用的背景是它是在postman中发送给我的,我可以运行它.我能够从邮递员身上拉出身体,但我需要在API调用中包含身份验证.

在此处输入代码

library(RCurl)

headerFields =
  c(Accept = "text/xml",
    'Content-Type' = "text/xml; charset=utf-8")

body = '<?xml version="1.0" encoding="UTF-8"?>
<SOAP-ENV:Envelope xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/" xmlns:ns1="http://www.sitename.com/bizconnect/SBU">
<SOAP-ENV:Body>
<ns1:GetSBUApplicationData>
<ns1:Subscriber>
<ns1:SubCode>123456</ns1:SubCode>
</ns1:Subscriber>
<ns1:UserID>xxxxxx</ns1:UserID>
<ns1:ReferenceID>A</ns1:ReferenceID>
<ns1:ResponseVersion>010</ns1:ResponseVersion>
<ns1:Application>
<ns1:Id>G020D</ns1:Id>
<ns1:Name/>
<ns1:Key>
<ns1:Field>
<ns1:Id>00920000</ns1:Id>
<ns1:Name/>
<ns1:Value>900000095</ns1:Value>
</ns1:Field>
</ns1:Key>
</ns1:Application>
</ns1:GetSBUApplicationData>
</SOAP-ENV:Body>
</SOAP-ENV:Envelope>'

curlPerform(url = "https://stg1-ss1.sitename.com/bizconnect/SBU/service",
            httpheader = headerFields,
            postfields = body
)
Run Code Online (Sandbox Code Playgroud)

小智 4

好的。目前,考虑到它在邮递员中运行良好,我将假设该服务正在使用基本身份验证运行。

在这种情况下,您不需要在 SOAP 信封中包含身份验证详细信息,而是在 HTTP 级别进行身份验证。

建议尝试这样的事情;

curlPerform(url = "https://stg1-ss1.sitename.com/bizconnect/SBU/service",
        httpheader = headerFields,
        postfields = body, userpwd = "user:password")
Run Code Online (Sandbox Code Playgroud)

有关更多详细信息,我建议查看 JStatSoft RCurl 论文的第 4.2 节,该论文位于: http: //www.omegahat.net/RCurl/RCurlJSS.pdf

我不太喜欢 inc 在代码文件中包含凭据,因此我还建议查看本文中有关如何将凭据外部化到单独的密码文件中的指南。这样您就不会意外地将凭据检查到版本控制中。