我正在尝试访问远程Web服务。能够像这样得到卷曲的良好反应:
class ViewController: UIViewController, UITableViewDataSource, UITableViewDelegate, HomeModelProtocal {
@IBOutlet weak var listTableView: UITableView!
var feedItems: NSArray = NSArray()
var selectedLocation : Parsexml = Parsexml()
override func viewDidLoad() {
super.viewDidLoad()
//set delegates and initialize homeModel
self.listTableView.delegate = self
self.listTableView.dataSource = self
let homeModel = HomeModel()
homeModel.delegate = self
homeModel.downloadItems()
func itemsDownloaded(items: NSArray) {
}
func tableView(tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
// Return the number of feed items
return feedItems.count
}
func tableView(tableView: UITableView!, cellForRowAtIndexPath indexPath: NSIndexPath!) -> UITableViewCell! {
let cellIdentifier: String = "BasicCell"
let myCell: UITableViewCell = tableView.dequeueReusableCell(withIdentifier: cellIdentifier)!
let item: Parsexml = feedItems[indexPath.row] as! Parsexml
myCell.textLabel!.text = item.title
return myCell
}
但是从java获取错误:
curl -X POST -H "Content-Type: text/xml" -k -H "SOAPAction:getUserActivity" --data @testFile.dat https://esp-int.my.company.com:443/UsageService/13.11
Java设置请求的安全部分,如下所示:
com.sun.xml.ws.client.ClientTransportException: request requires HTTP authentication: Unauthorized
其中用户名和密码与testFile.dat中的内容相同。
testFile.dat请求的安全性部分是:
String SECURITY_NAMESPACE = "http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd";
QName securityQName = new QName(SECURITY_NAMESPACE, "Security");
SOAPElement security = soapFactory.createElement(securityQName);
QName usernameTokenQName = new QName(SECURITY_NAMESPACE, "UsernameToken");
SOAPElement usernameToken = soapFactory.createElement(usernameTokenQName);
QName usernameQName = new QName(SECURITY_NAMESPACE, "Username");
SOAPElement theUsername = soapFactory.createElement(usernameQName);
theUsername.addTextNode(username);
QName passwordQName = new QName(SECURITY_NAMESPACE, "Password");
SOAPElement thePassword = soapFactory.createElement(passwordQName);
thePassword.addTextNode(password);
usernameToken.addChildElement(theUsername);
usernameToken.addChildElement(thePassword);
security.addChildElement(usernameToken);
有什么建议吗?
答案 0 :(得分:0)
我们在更改其网络服务的端点时必须添加以下两行
QName pwdTypeQName = new QName("Type");
thePassword.addAttribute(pwdTypeQName, "http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-username-token-profile-1.0#PasswordText");