- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我正在制作一个 ios 应用程序。我是 swift 的新手,无法理解我的代码。任何人都可以帮助我了解我的代码发生了什么。
这是添加电子邮件 ID 的登录应用程序,如果电子邮件存在,它应该转到下一个 View Controller ,如果不存在,那么它应该给出错误。我越来越难以理解我的代码。
这是我的代码:
class checkLoginViewController: UIViewController {
@IBOutlet weak var checkUsernametextfield: UITextField!
@IBAction func checkUsernameButton(_ sender: UIButton) {
print("Clicked On SUbmit !!!!")
//Read Value from Text
let email = checkUsernametextfield.text
let myUrl = URL(string: "http://192.168.0.117/rest/signup.php");
var request = URLRequest(url:myUrl!)
request.httpMethod = "POST"// Compose a query string
let postString = "email=\(String(describing: email))";
request.httpBody = postString.data(using: String.Encoding.utf8);
let task = URLSession.shared.dataTask(with: request) { (data: Data?, response: URLResponse?, error: Error?) in
if error != nil
{
print("error=\(String(describing: error))")
return
}
// You can print out response object
print("response = \(String(describing: response))")
//Let's convert response sent from a server side script to a NSDictionary object:
do {
let json = try JSONSerialization.jsonObject(with: data!, options: .mutableContainers) as? NSDictionary
if let parseJSON = json {
// Now we can access value of First Name by its key
let emailValue = parseJSON["email"] as? String
print("email: \(String(describing: emailValue))")
}
} catch {
print(error)
}
}
task.resume()
输出:
Clicked On SUbmit !!!! response = Optional( { URL: http://192.168.0.117/rest/signup.php } { Status Code: 200, Headers { Connection = ( "Keep-Alive" ); "Content-Length" = ( 61 ); "Content-Type" = ( "application/json" ); Date = ( "Mon, 12 Mar 2018 06:35:58 GMT" ); "Keep-Alive" = ( "timeout=5, max=100" ); Server = ( "Apache/2.4.27 (Ubuntu)" ); } }) email: nil
最佳答案
也许试试这个。希望它有效。
let url = URL(string:"http://192.168.0.117/rest/signup.php")
let parameters = ["email": checkUsernametextfield.text]
var request = URLRequest(url : url!)
request.httpMethod = "POST"
request.httpBody = try? JSONSerialization.data(withJSONObject:parameters, options: [])
request.addValue("application/json", forHTTPHeaderField: "Content-Type")
let session = URLSession.shared
session.dataTask(with: request, completionHandler: { (data, response, error) in
if let data = data {
do {
let json = try? JSONSerialization.jsonObject(with: data, options: []) as! Dictionary<String, Any>
if let json = json {
print("HERE SHOULD BE YOUR JSON \(json)")
}
}
} else {
print("Error \(String(describing: error?.localizedDescription))")
}
}).resume()
关于json - 如何在 swift 中使用 json 进行 HTTPRequest,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49231926/
假设我的客户端(浏览器)请求我的 java 服务(服务 A)。 http://localhost:8080/getDataFromB 根据服务 A 的请求,我需要向服务 B 或服务 C 发出另一个 H
我正在尝试调用 API 来检索数据列表,此数据将帮助我获取图像源。因此,对于每个数据条目,我尝试调用图像 url 并使用 Parse Image 进行一些图像处理。问题是,内部的 httpReques
当前代码 if (!(context.Exception is exception)) HttpContent requestContent = context.Request.Content
我有这个代码: You are browsing this site with: Or with Request.UserAgent: 第一个在浏览器
我正在使用 Django 和 TornadIO2/Tornado 编写一个 socket.io 应用程序。在 TonradIO2 session 中,我可以访问 Tornado 的 HTTPReque
用于确定用户代理的这两个属性之间有什么区别(如果有)和优点/缺点? Dim strUserAgt as String userAgent = Request.userAgent 对比 Dim strU
详情如下:https://docs.microsoft.com/en-us/dotnet/api/microsoft.aspnetcore.http.httprequest?view=aspnetco
我一直在关注我网站的性能,在所有执行缓慢的代码 (>1s) 中,超过 90% 是因为 System.Web.HttpRequest.GetEntireRawContent()(由 System.Web
我有一个后端服务,它接受授权 header 来验证访问。我使用 Spring cloud zuul 创建了一个网关服务,并将请求路由到后端服务。 网关服务本身受 OAuth2 保护,并接受授权 hea
是否可以在中间件函数中获取请求方法(GET、POST、PUT...)? $myMiddleware = function (Request $request) { // This is wha
代码如下: //Get请求方式 private string RequestGet(string Url) &n
在 .net Framework yield ok. // if is not valid var request = HttpContext.Current.Req
在用于 http get 和 post 的 angular 5.2.x 中,我有以下代码: post(url: string, model: any): Observable { return thi
我试图了解如何从Dart进行Ajax调用。我对Web编程的了解非常有限。 我的简单服务器ajax.py:- #!/usr/bin/env python from datetime import tim
我正在为Http GET请求创建包装器类,但是当我使用HttpRequest.request时,没有任何响应。如果我使用原始的HttpRequests使用等效的代码,则可以使用。 我想念什么吗?我正在
我正在尝试生成一个 jmeter 脚本,其中每次运行脚本时都会创建一个唯一的文件夹 - 将某种变量添加到文件夹名称中,例如用户名+时间戳,应该足以保证唯一性。然而,jmeter 并没有将变量解析为其值
我有一个网络应用程序,它有一个计时器,每 3 秒触发一次轮询以获取数据。它工作正常大约 2.5 分钟,然后 Chromium 崩溃。 我的请求 Dart 看起来像这样 HttpRequest.getS
我目前有一个函数,可以生成 httpRequest 并将接收到的 json 解析为 URL array 。我想在第一个请求完成并且数据解析后触发第二个 httpRequest ,在我尝试过的两种解决方
我试图像这样延迟我的 $http 调用: githubService.getUserEvents = function getUserEvents() { return $timeout
我正在运行 340 个并发用户以使用 jmeter 在服务器上进行负载测试。 但是在大多数情况下,jmeter 挂断并且不会返回,即使我尝试关闭连接它也只是挂断了。最终我不得不关闭应用程序。 任何想法
我是一名优秀的程序员,十分优秀!