我正在研究快速的SOAP网络服务,每件事情都很好,但是我得到了400错误,请求你们帮助我。
请查看以下链接
对于SOAPmessage ,
class ViewController:UIViewController,XMLParserDelegate {
var currentElement:String!
override func viewDidLoad() {
super.viewDidLoad()
let SqlQuery = "Select top 1 RTRSN,RTName,RTVILLANO,contactcellno,isnull(contactno,'-')as contactno,isnull(contactmail,'-')as contactmail,replace(Rtaddress1,',','^^')as Rtaddress1,isnull(cityname,'-')as cityname,isnull(pincode,'-')as pincode, isnull(country,'-')as country, convert(nvarchar(11),DOB,106)as DOB,isnull(marital_status,'-')as marital_status,isnull(Bloodgroup,'-')as Bloodgroup from tblResident where RTVILLANO='sdm 45' and contactcellno='9566703089'"
let Connname = "Data Source=.;Initial Catalog=Covaisoft;User ID=cpc;Password=C0va!C@re34&"
let is_SoapMessage: String = "<soap:Envelope xmlns:xsi='http://www.w3.org/2001/XMLSchema-instance' xmlns:xsd='http://www.w3.org/2001/XMLSchema' xmlns:soapenc='http://schemas.xmlsoap.org/soap/encoding/' xmlns:tns='http://www.bincrm.com/IFIPL/' xmlns:types='http://www.bincrm.com/IFIPL/encodedTypes' xmlns:soap='http://schemas.xmlsoap.org/soap/envelope/'><soap:Body soap:encodingStyle='http://schemas.xmlsoap.org/soap/encoding/'><tns:Select><Connname xsi:type='xsd:string'>\(Connname)</Connname><SqlQuery xsi:type='xsd:string'>\(SqlQuery)</SqlQuery></tns:Select></soap:Body></soap:Envelope>"
let is_URL: String = "http://www.bincrm.com/ifipl/IFIPLDetails.asmx"
let lobj_Request = NSMutableURLRequest(url: NSURL(string: is_URL)! as URL)
let session = URLSession.shared
var _: NSError?
lobj_Request.httpMethod = "POST"
lobj_Request.httpBody = is_SoapMessage.data(using: String.Encoding.utf8)
lobj_Request.addValue("www.bincrm.com", forHTTPHeaderField: "Host")
lobj_Request.addValue("text/xml; charset=utf-8", forHTTPHeaderField: "Content-Type")
// lobj_Request.addValue(String(count(is_SoapMessage)), forHTTPHeaderField: "Content-Length")
//lobj_Request.addValue("223", forHTTPHeaderField: "Content-Length")
lobj_Request.addValue("http://www.bincrm.com/IFIPL/Select", forHTTPHeaderField: "SOAPAction")
let task = session.dataTask(with: lobj_Request as URLRequest, completionHandler: {data, response, error -> Void in
print("Response: \(response!)")
let strData = NSString(data: data!, encoding: String.Encoding.utf8.rawValue)
print("Body: \(strData!)")
if error != nil
{
print("Error:\(String(describing: error))")
}
let xmlParser = XMLParser(data: data!)
xmlParser.delegate = self
xmlParser.parse()
xmlParser.shouldResolveExternalEntities = true
})
task.resume()
}
func parser(_ parser: XMLParser, didStartElement elementName: String, namespaceURI: String?, qualifiedName qName: String?, attributes attributeDict: [String : String]) {
currentElement = elementName
}
func parser(_ parser: XMLParser, foundCharacters string: String) {
if self.currentElement == "SelectResponse"
{
print("-------\(string)-------")
} }
override func didReceiveMemoryWarning() {
super.didReceiveMemoryWarning()
// Dispose of any resources that can be recreated.
}
}