
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 as Nsstring).stringByReplacingOccurrencesOfString("@",withString: "%40")let str = "name=\(email2)&pass=\(vIEwController!.password.text)&form_ID=user_login" as Nsstringlet d = str.dataUsingEnCoding(NSUTF8StringEnCoding)if let d2 = d { request.httpBody = d2 let urlConnection = NSURLConnection(request: request,delegate: self)} UPDATE
我把@ teamnorge的代码放在 *** 场上,进入一个空的Single VIEw Application项目.项目中返回的HTML包含Oops子字符串,在 *** 场中使用的代码不包含它,任何想法发生了什么,为什么同样的请求会产生不同的HTML结果?我也从iOS设备和模拟器也收到失败的消息.
UPDATE
删除NSURLRequest缓存,如here推荐,但仍然无法正常工作.和here.
UPDATE
试图删除所有凭据,如here,但没有帮助,没有发现任何凭据.
解决方法 看起来当您收到http 302和新的位置网址时,iOS会通过此URL自动获取页面,因此我猜您的响应实际上是重定向页面的HTML内容.请验证.更新:
import UIKitimport XCPlaygroundlet 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" as Nsstringlet d = str.dataUsingEnCoding(NSUTF8StringEnCoding)request.httpBody = drequest.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() 总结 以上是内存溢出为你收集整理的ios – NSURLRequest产生与HTTP代理客户端不同的结果全部内容,希望文章能够帮你解决ios – NSURLRequest产生与HTTP代理客户端不同的结果所遇到的程序开发问题。
如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。
欢迎分享,转载请注明来源:内存溢出
微信扫一扫
支付宝扫一扫
评论列表(0条)