ios – NSURLRequest产生与HTTP代理客户端不同的结果

ios – NSURLRequest产生与HTTP代理客户端不同的结果,第1张

概述我从HTTP代理客户端和NSURLRequest NSURLConnection发送相同的HTTP消息,并获得不同的结果.它是一个认证请求.从HTTP代理认证请求被接受,从应用程序发送不.为什么?接受意味着重定向后 HTML将不包含Oops子字符串. let url = NSURL(string: "http://www.swisshttp.weact.ch/en/user/login")let 我从http代理客户端和NSURLRequest NSURLConnection发送相同的http消息,并获得不同的结果.它是一个认证请求.从http代理认证请求被接受,从应用程序发送不.为什么?接受意味着重定向后 HTML将不包含Oops子字符串.

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代理客户端不同的结果所遇到的程序开发问题。

如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。

欢迎分享,转载请注明来源:内存溢出

原文地址:https://54852.com/web/1097967.html

(0)
打赏 微信扫一扫微信扫一扫 支付宝扫一扫支付宝扫一扫
上一篇 2022-05-28
下一篇2022-05-28

发表评论

登录后才能评论

评论列表(0条)

    保存