ios - NSURLRequest produce different result than HTTP proxy client -
i send same http message http proxy client , nsurlrequest + nsurlconnection, , different result. authentication request. http proxy authentication request accepted, sending app not. why? accepted means after redirection html contains no oops substring.
let url = nsurl(string: "http://www.swisshttp.weact.ch/en/user/login") let request = nsmutableurlrequest(url: url) request.httpmethod = "post" request.setvalue("application/x-www-form-urlencoded", forhttpheaderfield: "content-type")  let email2 = (viewcontroller!.email.text nsstring).stringbyreplacingoccurrencesofstring("@", withstring: "%40") let str = "name=\(email2)&pass=\(viewcontroller!.password.text)&form_id=user_login" nsstring let d = str.datausingencoding(nsutf8stringencoding) if let d2 = d {     request.httpbody = d2     let urlconnection = nsurlconnection(request: request, delegate: self) }   update
i have put @teamnorge's code below playground , empty single view application project. returned html in project contains oops substring, code used in playground not containes it, idea going on, why same request produce different html result? failed message ios device , simulator too.
update
removed nsurlrequest cache here recommended, still not works expected. , here.
update
tried remove credentials here, didn't help, no credential found.
it looks when receive http 302 , new location url, ios automatically fetch page url, guess response in fact html content of redirection page. please verify.
update:
import uikit import xcplayground  let url = nsurl(string: "http://www.swisshttp.weact.ch/en/user/login") let request = nsmutableurlrequest(url: url!) let str = "name=kukodajanos%40icloud.com&pass=jelszo&form_id=user_login"  nsstring let d = str.datausingencoding(nsutf8stringencoding) request.httpbody = d request.httpmethod = "post" request.setvalue("application/x-www-form-urlencoded", forhttpheaderfield: "content-type")  nsurlconnection.sendasynchronousrequest(request, queue:     nsoperationqueue.currentqueue()) { response, maybedata, error in    if let data = maybedata {        let contents = nsstring(data:data, encoding:nsutf8stringencoding)        println(contents)              if contents!.rangeofstring("oops").length == 0 {                  println("success")             } else {                 println("failed")             }    } else {        println(error.localizeddescription)    } }  xcpsetexecutionshouldcontinueindefinitely()      
Comments
Post a Comment