在我的 IOS swift Xcode7 API 将用户注册到我的站点后,如何从我的 Drupal 7 REST 服务返回用户 ID?控制台返回状态 200(正常),但不返回注册的 UID,我将需要它来实现更多功能。我还需要在此处包含哪些代码行,或者我可以将其添加为单独的 API?
这是我的代码:
import UIKit
import Foundation
import Alamofire
import SwiftyJSON
class submitVoteViewController: UIViewController {
override func viewDidLoad() {
super.viewDidLoad()
// Do any additional setup after loading the view.
print("loaded page1")
}
@IBAction func register(sender: AnyObject) {
// register user
let voteEndpoint: String = "https://www.example.com/ios1/user/register.json"
let newVote = ["account":["name":"example name", "mail":"examplemail@gmail.com", "pass":"examplepass", "status":1]]
Alamofire.request(.POST, voteEndpoint, parameters: newVote, encoding: .JSON)
.response { request, response, data, error in
print(request)
print (response)
print (error)
}
}
当我查找它时,Drupal 站点显示 UID 是 375(已阻止,尽管我已输入状态 1 以便用户处于事件状态?)。控制台响应是;
已加载第 1 页 可选({网址:https://www.example.com/ios1/user/register.json}) 可选({ URL:https://www.example.com/ios1/user/register.json } { 状态码:200,标题{ “缓存控制”=“无缓存,必须重新验证”; 连接=“保持事件”; “内容类型”=“应用程序/json”; Date = "2016 年 7 月 16 日星期六 23:03:37 GMT"; Expires = "Sun, 19 Nov 1978 05:00:00 GMT"; "Keep-Alive"= "超时=10,最大=200"; 服务器= Apache ; "Set-Cookie"= "DRUPAL_UID=0; expires=2016 年 7 月 15 日星期五 23:03:37 GMT; Max-Age=-86401; path=/; domain=.example.com; secure, DRUPAL_UID=- 1;到期=2016 年 8 月 9 日星期二 02:36:57 GMT;最大年龄=1999999;路径=/;域=.example.com;安全”; “传输编码”=身份; “X-Content-Type-Options”= nosniff; "X-Powered-By"= "PHP/5.6.9"; } }) 无
最佳答案
根据服务的响应,
HTTP/1.1 200 OK
Date: Sat, 23 Jul 2016 18:12:06 GMT
Server: Apache/2.4.17 (Unix) OpenSSL/1.0.1h mod_fcgid/2.3.9
X-Powered-By: PHP/5.6.19
Expires: Sun, 19 Nov 1978 05:00:00 GMT
Cache-Control: no-cache, must-revalidate, post-check=0, pre-check=0
X-Content-Type-Options: nosniff
Vary: Accept
Connection: close
Transfer-Encoding: chunked
Content-Type: application/json
{"uid":"3","uri":"http://drupal-7-43.dd/Api/v1/user/3"}
因此响应对象应该附加一个 uid。
H44f33z 的回答是正确的。
关于swift - 如何从用户注册 API 返回 UID,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38416536/