Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

"dataTaskWithRequest" requests the NSMutableRequest twice when only one request is required

I have a secure webView which shows the customer to Load his wallet . I pass secure information MPIN(like a one time password). There is problem with

@IBOutlet weak var loading: UIActivityIndicatorView!

@IBOutlet var lblLoading: UILabel!


@IBOutlet weak var mob_webview: UIWebView!

override func viewDidLoad()
{
    super.viewDidLoad()
    mob_webview.hidden = true
    mob_webview.delegate=self
    cmmn.createDatabase()
    linkgot = cmmn.geturl()

   link="http://*****************************************.jsp?"

    let request = NSMutableURLRequest(URL: NSURL(string: link)!)
    request.HTTPMethod = "POST"
    let postString = "recharge_type=\(_catcode)&amount=\(_amountfiled_got)&mobileNo=\(cmmn.getPhoneNumber())&prePostLan=\(prePostLan)&stdCode=\(_stdCode)&accNo=\(accNo)&deduct_frm=B&rcMobileNum=\(_numberfiled_got)&mobOperator=\(_merch_code)&operator=\(_operatr)&rcType=\(_rec_type)&mpin=\(_mpin)"
    request.HTTPBody = postString.dataUsingEncoding(NSUTF8StringEncoding)
    let task = NSURLSession.sharedSession().dataTaskWithRequest(request) {
        data, response, error in

        if error != nil {
            print("error=\(error)")
            return
        }

        print("response = \(response)")

        let responseString = NSString(data: data!, encoding: NSUTF8StringEncoding)
        print("responseString = \(responseString)")
    }
    task.resume()
    mob_webview.loadRequest(request)







    // Do any additional setup after loading the view.
}
func webViewDidFinishLoad(webView_Pages: UIWebView)
{

    mob_webview.hidden = false
    loading.hidden = true
    lblLoading.hidden=true
    print("OK")

}

Response in server log: enter image description here enter image description here

In the server ,If the user types the MPIN wrong three times, he gets blocked. This is done based on the number of wrong MPIN hits in the server. For some reason my web view makes the request twice (i.e. Calls the link which loads the request twice),even though its loaded just once.Suppose if customer enter wrong MPIN and load the web view, The link is called twice he looses 2 chances to enter correct MPIN. The android version of our APP works correctly with a similar kind of request.Any reason for it?

like image 483
Jeesson_7 Avatar asked Feb 05 '23 01:02

Jeesson_7


1 Answers

I gone through apple reference document after reading your question. It says then webViewDidFinishLoad is called after loading each frames in webview. Here is document

webViewDidFinishLoad: Sent after a web view finishes loading a frame.

Please check with server, that how many request is made for one run. it's 2 or one. Also want to know how many time your print statment in your code execute print("response = \(response)"). As I don't console for this statement.

Found in your question you calls NSURLSession dataTaskWithRequest and also load request in web view. That might also problem for calling same thing twice. If you want to open request in webview don't use NSURLSession task request. Run it by commenting task.resume().

like image 63
sschunara Avatar answered Feb 07 '23 19:02

sschunara