我有这样的控制器 -
def create
if (@user = User.find_by_email(params[:email])) && @user.valid_password?(params[:password])
render json: @user.as_json(only: [:email,:authentication_token]),status: :created
else
render json:('Unauthorized Access')
end
end
Run Code Online (Sandbox Code Playgroud)
当我使用Postman发出此请求时,我选择Body,并形成数据并添加电子邮件和密码.这个工作
如何使用swift做同样的事情?这就是我尝试过的
let url = URL(string: "http://localhost:3000/api/v1/user_serialized/")
let config = URLSessionConfiguration.default
let request = NSMutableURLRequest(url: url!)
request.httpMethod = "POST"
let bodyData = "email=Test@test.com&password=Test1234"
request.httpBody = bodyData.data(using: String.Encoding.utf8);
let session = URLSession(configuration: config)
let task = session.dataTask(with: url! as URL, completionHandler: {(data, response, error) in
let json = JSON(data:data!)
debugPrint(json)
})
task.resume()
Run Code Online (Sandbox Code Playgroud) 如果列表只包含0s,我如何在python中打印?
list1=[0,0,0,0,0,0]
if list1 has all 0s
print("something")
Run Code Online (Sandbox Code Playgroud)
我希望输出是"东西"
while index < len(diecount):
print(index)
for number in range(diecount[index]):
print('*')
index+=1
print("")
Run Code Online (Sandbox Code Playgroud)
目前我正在接受
1
**
2
3
**
Run Code Online (Sandbox Code Playgroud)
我希望输出
1 **
2
3 **
Run Code Online (Sandbox Code Playgroud) outcome=input("higher or lower")
while (outcome!= 'h' or outcome!= 'l'):
outcome=input("enter h or l")
print("its working")
Run Code Online (Sandbox Code Playgroud)
即使我写H或L,while循环仍然继续
如果事情属实,我如何结束我的计划?
这是我的代码
count=0
num=input("What would you like to do [1,2,3,4]? ")
while (num>'0' and num<'5'):
while num=='1':
Do something
while num=='2':
Do something
While num=='3':
Do something
while num=='4' and count!=1:
print("The End")
count= count+1
Run Code Online (Sandbox Code Playgroud)
我希望程序在num为'4'时结束