Requete vide
Bonjour tous le mondes,
Je vous écris depuis quelques jours je comprend pas j'essaye de faire un moteur de recherche avec un picker.
Cela fonctionne bien en premier lieux mais mon serveur reçus juste cela
IP_servuer - - [03/May/2017:13:51:11 +0200] "POST /lien _serveur/search.php HTTP/1.1" 200 20 "-" "domaine/1 CFNetwork/811.4.18 Darwin/16.5.0"
que cela devrait être :
IP_servuer - - [03/May/2017:13:51:11 +0200] "POST /lien _serveur/search.php?price=100&lang=fr HTTP/1.1" 200 20 "-" "domaine/1 CFNetwork/811.4.18 Darwin/16.5.0"
et je ne comprend pas j'ai bien fait comme les autre dan me log j'ai bien cela :
PostData: price=100&lang=fr
voilà mon code :
import UIKit
class SearchViewController: UIViewController {
@IBOutlet var menuButton:UIBarButtonItem!
@IBOutlet var extraButton:UIBarButtonItem!
// var tabInfos = String()
// var tabInfos1 = String()
let pickerData = ["100", "300", "1000 - 2500+"]
lazy var pickerView: UIPickerView =
{
let pickerView = UIPickerView()
pickerView.dataSource = self
pickerView.delegate = self
return pickerView
}()
@IBOutlet var textFields: [UITextField]!
var currentTextField: UITextField?
override func viewDidLoad() {
super.viewDidLoad()
if NetworkViewController.isConnectedToNetwork() == true
{
print("Internet connection OK")
}
else
{
print("Internet connection FAILED")
let alert = UIAlertController(title: "No Internet Connection", message: "Make sure your device is connected to the internet.", preferredStyle: .alert)
alert.addAction(UIAlertAction(title: "OK", style: .cancel, handler: nil))
self.present(alert, animated: true, completion: nil)
}
if revealViewController() != nil {
//revealViewController().rearViewRevealWidth = 62
menuButton.target = revealViewController()
menuButton.action = #selector(SWRevealViewController.revealToggle(_:))
revealViewController().rightViewRevealWidth = 230
extraButton.target = revealViewController()
extraButton.action = #selector(SWRevealViewController.rightRevealToggle(_:))
view.addGestureRecognizer(self.revealViewController().panGestureRecognizer())
}
for textField in self.textFields
{
textField.delegate = self
textField.inputView = pickerView
}
}
@IBAction func signinTapped(_ sender : UIButton) {
let textfield0:String = textFields[0].text! as String
let langStr:String = NSLocale.current.languageCode!
print("",langStr)
print("terrred",textfield0)
if ( textfield0.isEqual("") || (langStr.isEqual(""))) {
let alertView:UIAlertController = UIAlertController()
alertView.title = "Sign in Failed!"
alertView.message = "Please enter Username and Password"
// alertView.delegate = self
//alertView.addButton(withTitle: "OK")
// alertView.show()
} else {
do {
let post:NSString = "price=\(textfield0)&lang=\(langStr)" as NSString
NSLog("PostData: %@",post);
let url:URL = URL(string:"http://lien_serveur/search.php")!
let postData:Data = post.data(using: String.Encoding.utf8.rawValue)!
let postLength:NSString = String( postData.count ) as NSString
let request:NSMutableURLRequest = NSMutableURLRequest(url: url)
request.httpMethod = "POST"
request.httpBody = postData
request.setValue(postLength as String, forHTTPHeaderField: "Content-Length")
request.setValue("application/x-www-form-urlencoded", forHTTPHeaderField: "Content-Type")
request.setValue("application/json", forHTTPHeaderField: "Accept")
var reponseError: NSError?
var response: URLResponse?
var urlData: Data?
do {
urlData = try NSURLConnection.sendSynchronousRequest(request as URLRequest, returning:&response)
} catch let error as NSError {
reponseError = error
urlData = nil
}
if ( urlData != nil ) {
let res = response as! HTTPURLResponse!;
// NSLog("Response code: %ld", res?.statusCode);
if ((res?.statusCode)! >= 200 && (res?.statusCode)! < 300)
{
let responseData:NSString = NSString(data:urlData!, encoding:String.Encoding.utf8.rawValue)!
NSLog("Response ==> %@", responseData);
//var error: NSError?
let jsonData:NSDictionary = try JSONSerialization.jsonObject(with: urlData!, options:JSONSerialization.ReadingOptions.mutableContainers ) as! NSDictionary
let success:NSInteger = jsonData.value(forKey: "success") as! NSInteger
NSLog("Success: %ld", success);
if(success == 1)
{
NSLog("SEARCH SUCCESS");
let prefs:UserDefaults = UserDefaults.standard
prefs.set(1, forKey: "ISLOGGEDIN")
prefs.synchronize()
self.dismiss(animated: true, completion: nil)
let alert = UIAlertController(title: "super", message: "You have already deposited an avieSSSSSSSSS", preferredStyle: .alert)
alert.addAction(UIAlertAction(title: "OK", style: .cancel, handler: nil))
self.present(alert, animated: true, completion: nil)
} else {
var error_msg:String
if jsonData["error_message"] as? String != nil {
error_msg = jsonData["error_message"] as! String
} else {
error_msg = "Unknown Error"
}
let alert = UIAlertController(title: "Error", message: "SEARCH", preferredStyle: .alert)
alert.addAction(UIAlertAction(title: "OK", style: .cancel, handler: nil))
self.present(alert, animated: true, completion: nil)
}
} else {
let alert = UIAlertController(title: "Error", message: "Sign in Failed!", preferredStyle: .alert)
alert.addAction(UIAlertAction(title: "OK", style: .cancel, handler: nil))
self.present(alert, animated: true, completion: nil)
}
} else {
let alertView:UIAlertController = UIAlertController()
alertView.title = "Sign in Failed!"
alertView.message = "Connection Failure"
if let error = reponseError {
alertView.message = (error.localizedDescription)
}
}
} catch {
let alert = UIAlertController(title: "Error", message: "Sign in Failed!", preferredStyle: .alert)
alert.addAction(UIAlertAction(title: "OK", style: .cancel, handler: nil))
self.present(alert, animated: true, completion: nil)
}
}
}
@IBAction func tapView(_ sender: UITapGestureRecognizer)
{
self.currentTextField?.endEditing(true)
}
}
extension SearchViewController : UIPickerViewDataSource
{
func numberOfComponents(in pickerView: UIPickerView) -> Int
{
return 1
}
func pickerView(_ pickerView: UIPickerView, numberOfRowsInComponent component: Int) -> Int
{
return self.pickerData.count
}
}
extension SearchViewController : UIPickerViewDelegate
{
func pickerView(_ pickerView: UIPickerView, titleForRow row: Int, forComponent component: Int) -> String?
{
return self.pickerData[row]
}
func pickerView(_ pickerView: UIPickerView, didSelectRow row: Int, inComponent component: Int)
{
self.currentTextField?.text = pickerData[row]
self.currentTextField?.endEditing(true)
}
}
extension SearchViewController : UITextFieldDelegate
{
func textFieldDidBeginEditing(_ textField: UITextField)
{
self.currentTextField = textField
self.pickerView.selectRow(pickerData.index(of: self.currentTextField?.text ?? "")!, inComponent: 0, animated: false)
}
func textFieldDidEndEditing(_ textField: UITextField)
{
self.currentTextField = nil
}
}
et quant le clic sur SEARCH cela ouvre un autre storyboard avec le résultat.
Quelqu'un peux m'aider S.V.P
Merci pour vos différente aide,
Réponses
Bonjour,
J'ai résolut mon problème comme cela :