- android - RelativeLayout 背景可绘制重叠内容
- android - 如何链接 cpufeatures lib 以获取 native android 库?
- java - OnItemClickListener 不起作用,但 OnLongItemClickListener 在自定义 ListView 中起作用
- java - Android 文件转字符串
首先,我认为这是不可能的,但我有一段代码可以向数据库发出发布请求,我希望根据发布的数据获得响应。我的意思是,如果将变量放在数据库中,则响应将是“ok”,否则将是“no”。
我的发帖请求如下:
let postDataURL = "https://www.webpage.com/login_app.php"
let url: NSURL = NSURL(string: postDataURL)!
let request: NSMutableURLRequest = NSMutableURLRequest(url:url as URL)
let paramString = "precio=\(precio)&texto=\(texto)&user=\(user)&l_origen=\(l_origen)&l_destino=\(l_destino)&num_pal=\(num_pal)"
request.httpMethod = "POST"
request.httpBody = paramString.data(using: String.Encoding.utf8)
NSURLConnection.sendAsynchronousRequest(request as URLRequest, queue: OperationQueue.main) { (response, data, error) in
print(response!)
if let httpResponse = response as? HTTPURLResponse {
let statusCode = httpResponse.statusCode
if statusCode==200 {
print("Connection Successful")
} else {
print("Connection Failed (!200)")
}
}
}
然后,在 php
端我可以有类似的东西
if (affected_rows > 0){
$response = "ok";
} else {
$response = "no";
}
但在那之后,我不知道 php 代码将如何重新连接到设备以给它响应。
非常感谢您的宝贵时间。
编辑
失败时发送的响应:
Optional(<!DOCTYPE html>
<html>
<head>
<meta http-equiv="X-UA-Compatible" content="IE=EmulateIE11">
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Log in - Siens Translation</title>
.
.
.
</body>
</html>
)
这基本上是页面的 html 部分。
PHP 部分
<!DOCTYPE html>
<?php
require "class.logsys.php";
header('Content-Type: text/html; charset=utf-8' );
ini_set('default_charset', 'utf-8');
error_reporting(E_ERROR | E_WARNING | E_PARSE);
session_start();
\Fr\LS::init();
if(isset($_POST['action_login'])){
$identification = $_POST['login'];
$password = $_POST['password'];
if($identification == "" || $password == ""){
$msg = array("Error", "Username / Password Wrong !");
}else{
$login = \Fr\LS::login($identification, $password, isset($_POST['remember_me']));
if($login === false){
$msg = array("Error", "Username / Password Wrong !");
}else if(is_array($login) && $login['status'] == "blocked"){
$msg = array("Error", "Too many login attempts. You can attempt login after ". $login['minutes'] ." minutes (". $login['seconds'] ." seconds)");
}
}
}
$precio = $_POST['precio'];
$texto = $_POST['texto'];
$texto_ant = $_POST['texto_ant'];
$user = $_POST['user'];
$pass = $_POST['pass'];
$l_origen = $_POST['l_origen'];
$l_destino = $_POST['l_destino'];
$num_pal = $_POST['num_pal'];
$modificado = $_POST['modificado'];
$login = \Fr\LS::login($user, $pass, false, false);
if($login === true){
define('HOST','');
define('USER','');
define('PASS','');
define('DB','');
$con = mysqli_connect(HOST,USER,PASS,DB) or die('Unable to Connect');
mysqli_set_charset( $con, 'utf8');
if($modificado!='Si'){
$sql = "UPDATE users SET precio='$precio', text_cli='$texto', l_origen='$l_origen', l_destino='$l_destino', num_pal='$num_pal' WHERE username='$user' AND text_cli='' LIMIT 1 ";
mysqli_query($con,$sql);
echo '{"success":true}';
if(mysqli_affected_rows($con)==0){
$sql2 = "UPDATE users SET precio2='$precio', text_cli2='$texto', l_origen2='$l_origen', l_destino2='$l_destino', num_pal2='$num_pal' WHERE username='$user' AND text_cli2='' LIMIT 1 ";
mysqli_query($con,$sql2);
}
if(mysqli_affected_rows($con)==0) {
$sql3 = "UPDATE users SET precio3='$precio', text_cli3='$texto', l_origen3='$l_origen', l_destino3='$l_destino', num_pal3='$num_pal' WHERE username='$user' AND text_cli3='' LIMIT 1 ";
mysqli_query($con,$sql3);
}
if(mysqli_affected_rows($con)==0) {
$sql4 = "UPDATE users SET precio4='$precio', text_cli4='$texto', l_origen4='$l_origen', l_destino4='$l_destino', num_pal4='$num_pal' WHERE username='$user' AND text_cli4='' LIMIT 1 ";
mysqli_query($con,$sql4);
}
if(mysqli_affected_rows($con)==0) {
$sql5 = "UPDATE users SET precio5='$precio', text_cli5='$texto', l_origen5='$l_origen', l_destino5='$l_destino', num_pal5='$num_pal' WHERE username='$user' AND text_cli5='' LIMIT 1 ";
mysqli_query($con,$sql5);
}
if(mysqli_affected_rows($con)==0) {
$sql6 = "UPDATE users SET precio6='$precio', text_cli6='$texto', l_origen6='$l_origen', l_destino6='$l_destino', num_pal6='$num_pal' WHERE username='$user' AND text_cli6='' LIMIT 1 ";
mysqli_query($con,$sql6);
}
if(mysqli_affected_rows($con)==0) {
$sql7 = "UPDATE users SET precio7='$precio', text_cli7='$texto', l_origen7='$l_origen', l_destino7='$l_destino', num_pal7='$num_pal' WHERE username='$user' AND text_cli7='' LIMIT 1 ";
mysqli_query($con,$sql7);
}
if(mysqli_affected_rows($con)==0) {
$sql8 = "UPDATE users SET precio8='$precio', text_cli8='$texto', l_origen8='$l_origen', l_destino8='$l_destino', num_pal8='$num_pal' WHERE username='$user' AND text_cli8='' LIMIT 1 ";
mysqli_query($con,$sql8);
}
if(mysqli_affected_rows($con)==0) {
$sql9 = "UPDATE users SET precio9='$precio', text_cli9='$texto', l_origen9='$l_origen', l_destino9='$l_destino', num_pal9='$num_pal' WHERE username='$user' AND text_cli9='' LIMIT 1 ";
mysqli_query($con,$sql9);
}
if(mysqli_affected_rows($con)==0) {
$sql10 = "UPDATE users SET precio10='$precio', text_cli10='$texto', l_origen10='$l_origen', l_destino10='$l_destino', num_pal10='$num_pal' WHERE username='$user' AND text_cli10='' LIMIT 1 ";
mysqli_query($con,$sql10);
echo '{"success":false}';
}
$sql11 = "UPDATE users SET text_cli='$texto' WHERE ((l_origen='$l_origen' || l_origen2='$l_origen') AND l_destino='$l_destino' AND text_cli='' AND role='trad_app') LIMIT 1 ";
mysqli_query($con,$sql11);
if(mysqli_affected_rows($con)==0){
$sql12 = "UPDATE users SET text_cli2='$texto' WHERE ((l_origen='$l_origen' || l_origen2='$l_origen') AND l_destino='$l_destino' AND text_cli2='' AND role ='trad_app') LIMIT 1 ";
mysqli_query($con,$sql12);
}
if(mysqli_affected_rows($con)==0){
$sql13 = "UPDATE users SET text_cli3='$texto' WHERE ((l_origen='$l_origen' || l_origen2='$l_origen') AND l_destino='$l_destino' AND text_cli3='' AND role ='trad_app') LIMIT 1 ";
mysqli_query($con,$sql13);
}
if(mysqli_affected_rows($con)==0){
$sql14 = "UPDATE users SET text_cli4='$texto' WHERE ((l_origen='$l_origen' || l_origen2='$l_origen') AND l_destino='$l_destino' AND text_cli4='' AND role ='trad_app') LIMIT 1 ";
mysqli_query($con,$sql14);
}
if(mysqli_affected_rows($con)==0){
$sql15 = "UPDATE users SET text_cli5='$texto' WHERE ((l_origen='$l_origen' || l_origen2='$l_origen') AND l_destino='$l_destino' AND text_cli5='' AND role ='trad_app') LIMIT 1 ";
mysqli_query($con,$sql15);
}
if(mysqli_affected_rows($con)==0){
$sql16 = "UPDATE users SET text_cli6='$texto' WHERE ((l_origen='$l_origen' || l_origen2='$l_origen') AND l_destino='$l_destino' AND text_cli6='' AND role ='trad_app') LIMIT 1 ";
mysqli_query($con,$sql16);
}
if(mysqli_affected_rows($con)==0){
$sql17 = "UPDATE users SET text_cli7='$texto' WHERE ((l_origen='$l_origen' || l_origen2='$l_origen') AND l_destino='$l_destino' AND text_cli7='' AND role ='trad_app') LIMIT 1 ";
mysqli_query($con,$sql17);
}
if(mysqli_affected_rows($con)==0){
$sql18 = "UPDATE users SET text_cli8='$texto' WHERE ((l_origen='$l_origen' || l_origen2='$l_origen') AND l_destino='$l_destino' AND text_cli8='' AND role ='trad_app') LIMIT 1 ";
mysqli_query($con,$sql18);
}
if(mysqli_affected_rows($con)==0){
$sql19 = "UPDATE users SET text_cli9='$texto' WHERE ((l_origen='$l_origen' || l_origen2='$l_origen') AND l_destino='$l_destino' AND text_cli9='' AND role ='trad_app') LIMIT 1 ";
mysqli_query($con,$sql19);
}
if(mysqli_affected_rows($con)==0){
$sql20 = "UPDATE users SET text_cli10='$texto' WHERE ((l_origen='$l_origen' || l_origen2='$l_origen') AND l_destino='$l_destino' AND text_cli10='' AND role ='trad_app') LIMIT 1 ";
mysqli_query($con,$sql20);
}
}
if($modificado=='Si'){
$sql = "UPDATE users SET `text_cli`='$texto', `l_origen` = '$l_origen', `precio` = '$precio', `l_destino` = '$l_destino', `num_pal` = '$num_pal' WHERE text_cli = '$texto_ant' AND `role` = ''";
mysqli_query($con,$sql);
if(mysqli_affected_rows($con)==0){
$sql = "UPDATE users SET `text_cli2`='$texto', `l_origen2` = '$l_origen', `precio2` = '$precio', `l_destino2` = '$l_destino', `num_pal2` = '$num_pal' WHERE text_cli2 = '$texto_ant' AND `role` = ''";
mysqli_query($con,$sql);
}
if(mysqli_affected_rows($con)==0){
$sql = "UPDATE users SET `text_cli3`='$texto', `l_origen3` = '$l_origen', `precio3` = '$precio', `l_destino3` = '$l_destino', `num_pal3` = '$num_pal' WHERE text_cli3 = '$texto_ant' AND `role` = ''";
mysqli_query($con,$sql);
}
if(mysqli_affected_rows($con)==0){
$sql = "UPDATE users SET `text_cli4`='$texto', `l_origen4` = '$l_origen', `precio4` = '$precio', `l_destino4` = '$l_destino', `num_pal4` = '$num_pal' WHERE text_cli4 = '$texto_ant' AND `role` = ''";
mysqli_query($con,$sql);
}
if(mysqli_affected_rows($con)==0){
$sql = "UPDATE users SET `text_cli5`='$texto', `l_origen5` = '$l_origen', `precio5` = '$precio', `l_destino5` = '$l_destino', `num_pal5` = '$num_pal' WHERE text_cli5 = '$texto_ant' AND `role` = ''";
mysqli_query($con,$sql);
}
if(mysqli_affected_rows($con)==0){
$sql = "UPDATE users SET `text_cli6`='$texto', `l_origen6` = '$l_origen', `precio6` = '$precio', `l_destino6` = '$l_destino', `num_pal6` = '$num_pal' WHERE text_cli6 = '$texto_ant' AND `role` = ''";
mysqli_query($con,$sql);
}
if(mysqli_affected_rows($con)==0){
$sql = "UPDATE users SET `text_cli7`='$texto', `l_origen7` = '$l_origen', `precio7` = '$precio', `l_destino7` = '$l_destino', `num_pal7` = '$num_pal' WHERE text_cli7 = '$texto_ant' AND `role` = ''";
mysqli_query($con,$sql);
}
if(mysqli_affected_rows($con)==0){
$sql = "UPDATE users SET `text_cli8`='$texto', `l_origen8` = '$l_origen', `precio8` = '$precio', `l_destino8` = '$l_destino', `num_pal8` = '$num_pal' WHERE text_cli8 = '$texto_ant' AND `role` = ''";
mysqli_query($con,$sql);
}
if(mysqli_affected_rows($con)==0){
$sql = "UPDATE users SET `text_cli9`='$texto', `l_origen9` = '$l_origen', `precio9` = '$precio', `l_destino9` = '$l_destino', `num_pal9` = '$num_pal' WHERE text_cli9 = '$texto_ant' AND `role` = ''";
mysqli_query($con,$sql);
}
if(mysqli_affected_rows($con)==0){
$sql = "UPDATE users SET `text_cli10`='$texto', `l_origen10` = '$l_origen', `precio10` = '$precio', `l_destino10` = '$l_destino', `num_pal10` = '$num_pal' WHERE text_cli10 = '$texto_ant' AND `role` = ''";
mysqli_query($con,$sql);
}
$sql = "UPDATE users SET text_cli='$texto' WHERE text_cli = '$texto_ant' AND `role` = 'trad_app' ";
mysqli_query($con,$sql);
if(mysqli_affected_rows($con)==0){
$sql = "UPDATE users SET text_cli2='$texto' WHERE text_cli2 = '$texto_ant' AND `role` = 'trad_app' ";
mysqli_query($con,$sql);
}
if(mysqli_affected_rows($con)==0){
$sql = "UPDATE users SET text_cli3='$texto' WHERE text_cli3 = '$texto_ant' AND `role` = 'trad_app' ";
mysqli_query($con,$sql);
}
if(mysqli_affected_rows($con)==0){
$sql = "UPDATE users SET text_cli4='$texto' WHERE text_cli4 = '$texto_ant' AND `role` = 'trad_app' ";
mysqli_query($con,$sql);
}
if(mysqli_affected_rows($con)==0){
$sql = "UPDATE users SET text_cli5='$texto' WHERE text_cli5 = '$texto_ant' AND `role` = 'trad_app' ";
mysqli_query($con,$sql);
}
if(mysqli_affected_rows($con)==0){
$sql = "UPDATE users SET text_cli6='$texto' WHERE text_cli6 = '$texto_ant' AND `role` = 'trad_app' ";
mysqli_query($con,$sql);
}
if(mysqli_affected_rows($con)==0){
$sql = "UPDATE users SET text_cli7='$texto' WHERE text_cli7 = '$texto_ant' AND `role` = 'trad_app' ";
mysqli_query($con,$sql);
}
if(mysqli_affected_rows($con)==0){
$sql = "UPDATE users SET text_cli8='$texto' WHERE text_cli8 = '$texto_ant' AND `role` = 'trad_app' ";
mysqli_query($con,$sql);
}
if(mysqli_affected_rows($con)==0){
$sql = "UPDATE users SET text_cli9='$texto' WHERE text_cli9 = '$texto_ant' AND `role` = 'trad_app' ";
mysqli_query($con,$sql);
}
if(mysqli_affected_rows($con)==0){
$sql = "UPDATE users SET text_cli10='$texto' WHERE text_cli10 = '$texto_ant' AND `role` = 'trad_app' ";
mysqli_query($con,$sql);
}
}
mysqli_close($con);
}
?>
<html>
<head>
<meta http-equiv="X-UA-Compatible" content="IE=EmulateIE11">
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Log in - Siens Translation</title>
<link rel="icon" href="ordenador/ingles/css_imagenes/favicon.ico" type="image/x-icon" />
<link rel="shortcut icon" href="ordenador/ingles/css_imagenes/favicon.ico" type="image/x-icon" />
<link href="ordenador/ingles/nuestra_firma_estilos.css" rel="stylesheet" type="text/css">
<link href="ordenador/ingles/css/style4.css" rel="stylesheet" type="text/css">
<link href="movil/castellano/menu/menu.css" rel="stylesheet" type="text/css">
<link href="ordenador/ingles/css_resolutions/resolution800x600.css" rel="stylesheet" type="text/css">
<link href="ordenador/ingles/css_resolutions/resolution1024x600.css" rel="stylesheet" type="text/css">
<link href="ordenador/ingles/css_resolutions/resolution1366x768.css" rel="stylesheet" type="text/css"/>
<link href="ordenador/ingles/css_resolutions/resolution1280x600.css" rel="stylesheet" type="text/css"/>
<link href="ordenador/castellano/area_clientes/css/css_login.css" rel="stylesheet" type="text/css">
<link href="movil/castellano/menu/fonts.css" rel="stylesheet" type="text/css">
</head>
<body>
<div class="menu_bar" style="font-family:'Gotham-Bold';">
<a class="bt-menu" style="font-size:600%; font-family:'Gotham-Bold'"><span class="icon-menu"></span>Siens App<br><p style="font-size:25%; font- family:'Gotham-Light';">From</p></a>
</div>
<div id="login">
<div id="centrar_app">
<form action="login_app.php" method="POST" style="margin:0px auto;display:table;">
<label>
<p style="font-size:600%">Log in </p><br><br><br>
</label>
<label>
<p style="font-size:400%">Username</p><br>
<input style="padding-left:15px; border: 2px solid #475678; font-size:200%; height:100%" id="cuadro" name="login" type="text" value="<?php if(isset($_GET['user'])){ $user = $_GET['user']; echo $user; } ?>" />
</label><br><br><br>
<label>
<p style="font-size:400%">Password</p><br>
<input style="padding-left:15px; border: 2px solid #475678; font-size:200%; height:100%" id="cuadro" name="password" type="password" value="<?php if(isset($_GET['pass'])){ $pass = $_GET['pass']; echo $pass; } ?>" />
</label><br><a style="color:white; text-decoration:underline" href="ordenador/castellano/area_clientes/forgotpass.php">Forgot password?</a><br><br>
<label>
<p>
<input type="checkbox" name="remember_me" /> Remember me
</p>
</label><br>
<div clear></div>
<button id="login-button" style="font-size:400%;"
name="action_login">Access</button><br><br>
</form>
<style>
input[type=text], input[type=password]{
width: 230px;
}
</style>
<button id="login-button" style="font-size:400%"
onclick="location.href='';">Register</button><br><br>
<div id="thawteseal" style="text-align:center;" title="Click to Verify - This site chose Thawte SSL for secure e-commerce and confidential communications.">
<div><script type="text/javascript" src="https://seal.thawte.com/getthawteseal?host_name=&size=S&lang=en"></script></div>
</div>
</div>
</div>
<div id="login">
<div id="centrar_app">
<a onMouseOver="this.style.color='white'">If you can't access our payment zone Gateway, you need to deactivate "Block Cookies" in your iPhone configuration settings.</a>
</div>
</div>
<div style="margin-top:10rem" align="center">
<img style="width: 20%; height: 20%" src="">
</div>
最佳答案
您的服务器根本不需要“重新连接”到设备/客户端,POST 不是即发即弃。客户端与服务器建立连接,发送请求并等待服务器的响应。
您的服务器有机会完全按照您的意愿行事。它可以简单地回复你想要的 - 结果将是 response
的一部分或 data
在 sendAsynchronousRequest
的回调中.现在你的 php 代码没有打印任何东西,但是尝试 echo
东西,在 swift 回调中设置一个断点并检查回调对象包含的内容以及它们与您的内容的关系 echo
在服务器上编辑。
关于ios - 发布请求后发回响应,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41891556/
IO 设备如何知道属于它的内存中的值在memory mapped IO 中发生了变化? ? 例如,假设内存地址 0 专用于保存 VGA 设备的背景颜色。当我们更改 memory[0] 中的值时,VGA
我目前正在开发一个使用Facebook sdk登录(通过FBLoginView)的iOS应用。 一切正常,除了那些拥有较旧版本的facebook的人。 当他们按下“使用Facebook登录”按钮时,他
假设我有: this - is an - example - with some - dashesNSRange将使用`rangeOfString:@“-”拾取“-”的第一个实例,但是如果我只想要最后
Card.io SDK提供以下详细信息: 卡号,有效期,月份,年份,CVV和邮政编码。 如何从此SDK获取国家名称。 - (void)userDidProvideCreditCardInfo:(Car
iOS 应用程序如何从网络服务下载图片并在安装过程中将它们安装到用户的 iOS 设备上?可能吗? 最佳答案 您无法控制应用在用户设备上的安装,因此无法在安装过程中下载其他数据。 只需在安装后首次启动应
我曾经开发过一款企业版 iOS 产品,我们公司曾将其出售给大型企业,供他们的员工使用。 该应用程序通过 AppStore 提供,企业用户获得了公司特定的配置文件(包含应用程序配置文件)以启用他们有权使
我正在尝试将 Card.io SDK 集成到我的 iOS 应用程序中。我想为 CardIO ui 做一个简单的本地化,如更改取消按钮标题或“在此保留信用卡”提示文本。 我在 github 上找到了这个
我正在使用 CardIOView 和 CardIOViewDelegate 类,没有可以设置为 YES 的 BOOL 来扫描 collectCardholderName。我可以看到它在 CardIOP
我有一个集成了通话工具包的 voip 应用程序。每次我从我的 voip 应用程序调用时,都会在 native 电话应用程序中创建一个新的最近通话记录。我在 voip 应用程序中也有自定义联系人(电话应
iOS 应用程序如何知道应用程序打开时屏幕上是否已经有键盘?应用程序运行后,它可以接收键盘显示/隐藏通知。但是,如果应用程序在分屏模式下作为辅助应用程序打开,而主应用程序已经显示键盘,则辅助应用程序不
我在模拟器中收到以下错误: ImageIO: CGImageReadSessionGetCachedImageBlockData *** CGImageReadSessionGetCachedIm
如 Apple 文档所示,可以通过 EAAccessory Framework 与经过认证的配件(由 Apple 认证)进行通信。但是我有点困惑,因为一些帖子告诉我它也可以通过 CoreBluetoo
尽管现在的调试器已经很不错了,但有时找出应用程序中正在发生的事情的最好方法仍然是古老的 NSLog。当您连接到计算机时,这样做很容易; Xcode 会帮助弹出日志查看器面板,然后就可以了。当您不在办公
在我的 iOS 应用程序中,我定义了一些兴趣点。其中一些有一个 Kontakt.io 信标的名称,它绑定(bind)到一个特定的 PoI(我的意思是通常贴在信标标签上的名称)。现在我想在附近发现信标,
我正在为警报提示创建一个 trigger.io 插件。尝试从警报提示返回数据。这是我的代码: // Prompt + (void)show_prompt:(ForgeTask*)task{
您好,我是 Apple iOS 的新手。我阅读并搜索了很多关于推送通知的文章,但我没有发现任何关于 APNS 从 io4 到 ios 6 的新更新的信息。任何人都可以向我提供 APNS 如何在 ios
UITabBar 的高度似乎在 iOS 7 和 8/9/10/11 之间发生了变化。我发布这个问题是为了让其他人轻松找到答案。 那么:在 iPhone 和 iPad 上的 iOS 8/9/10/11
我想我可以针对不同的 iOS 版本使用不同的 Storyboard。 由于 UI 的差异,我将创建下一个 Storyboard: Main_iPhone.storyboard Main_iPad.st
我正在写一些东西,我将使用设备的 iTunes 库中的一部分音轨来覆盖 2 个视频的组合,例如: AVMutableComposition* mixComposition = [[AVMutableC
我创建了一个简单的 iOS 程序,可以顺利编译并在 iPad 模拟器上运行良好。当我告诉 XCode 4 使用我连接的 iPad 设备时,无法编译相同的程序。问题似乎是当我尝试使用附加的 iPad 时
我是一名优秀的程序员,十分优秀!