Tag: nsurlrequest

使用SOAP Web服务时,“没有findAction头”错误消息

在iOS应用程序中使用SOAP web服务时遇到以下错误 "No Action header was found with namespace 'http://www.w3.org/2005/08/addressing' for the given message." 同样的webservice在SOAP UI工具中工作正常。 以下是请求格式 NSString *data = @"<soap:Envelope xmlns:soap=\"http://www.w3.org/2003/05/soap-envelope\" xmlns:tem=\"http://tempuri.org/\"> <soap:Header></soap:Header> <soap:Body><tem:GetEvaluators></tem:GetEvaluators></soap:Body> </soap:Envelope>"; NSString *url = @"webservice url"; NSData *postData = [data dataUsingEncoding:NSUTF8StringEncoding allowLossyConversion:YES]; NSString *postLength = [NSString stringWithFormat:@"%d", [postData length]]; NSMutableURLRequest *request = [[NSMutableURLRequest alloc] init]; [request setURL:[NSURL URLWithString:url]]; [request setHTTPMethod:@"POST"]; […]

锁屏中断NSURLConnection

当用户locking和解锁iPad屏幕时,我想知道幕后发生了什么。 我有一个应用程序,使用NSURLConnection下载文件和下载失败与SOAP错误(“具有指定主机名的服务器无法find”),但不是当用户locking屏幕,但当它解锁它。 不pipepopup错误的时候,下载都不会结束。 任何想法为什么和可以做些什么呢? NSMutableURLRequest* request = [NSMutableURLRequest requestWithURL:url cachePolicy:NSURLRequestUseProtocolCachePolicy timeoutInterval:300]; NSURLConnection* conn = [[NSURLConnection alloc] initWithRequest: request delegate: self]; 从我可以告诉的是,当我点击主页button,我得到: applicationWillResignActive applicationDidEnterBackground 在三分钟后我回想起应用程序后,我得到: applicationWillEnterForeground 并且下载或者已经完成或者甚至在后台进行。 当我在后台更长的时间(5分钟),它超时出错。 当我locking屏幕时,我得到相同的应用程序状态的顺序,但也是关于下载断开的错误消息。 谢谢!

NSURLRequest:如何处理redirect的post?

我有一个久经考验的使用NSURLRequest(和伴奏)的实现,这对于GETs很有效,而POSTs则是给定的URL。 不过,我现在想移动URL的目标,而不更改应用程序使用的URL,所以我打算通过我的DNS提供商使用networkingredirect。 这对GET请求正常工作,但POST只是挂起…没有连接响应收到。 处理redirect的相关iOS方法是, -(NSURLRequest *)connection:(NSURLConnection *)connection willSendRequest:(NSURLRequest *)request redirectResponse:(NSURLResponse *)redirectResponse 根据苹果的文档( 处理redirect ), 如果委托没有实现连接:willSendRequest:redirectResponse :,所有规范的更改和服务器redirect都是允许的。 那么,这不是我的经验,因为离开这个方法不适合我。 请求只是挂起而没有回应。 苹果还build议实施willSendRequest(请参阅上面的链接苹果文档),这再也不适用于我。 我看到了调用,但结果请求只是挂起。 我目前的willSendRequest实现如下(见下文)。 这遵循redirect,但是将请求处理为GET,而不是POST。 我相信问题是redirect正在失去HTTP请求是一个POST的事实(可能还有更多的问题,比如向前移动请求Body?)。 我不确定我应该在这里做什么。 所以任何关于如何正确处理接收redirect的POST的build议将不胜感激。 谢谢。 -(NSURLRequest *)connection:(NSURLConnection *)connection willSendRequest:(NSURLRequest *)request redirectResponse:(NSURLResponse *)redirectResponse { NSHTTPURLResponse *httpResponse = (NSHTTPURLResponse *) redirectResponse; int statusCode = [httpResponse statusCode]; NSLog (@"HTTP status %d", statusCode); // http statuscodes between 300 […]

请求NSURLRequest

我试图做一个使用数据库的应用程序(实际上在我的本地主机),我尝试使用ASIHTTPRequest,但有这么多麻烦与iOS 5(我学会了如何使用ASIHTTPRequestforms: http ://www.raywenderlich.com / 2965 /如何到写的-IOS-APP-该用途-A-Web服务 现在我想用苹果提供的API:NSURLRequest / NSURLConnection等,… 我阅读了苹果在线指南,并创build了第一个代码: – (void)viewDidLoad { [super viewDidLoad]; // Do any additional setup after loading the view, typically from a nib. NSURLRequest *request = [NSURLRequest requestWithURL:[NSURL URLWithString:@"http://localhost:8888/testNSURL/index.php"] cachePolicy:NSURLRequestUseProtocolCachePolicy timeoutInterval:60.0]; [request setValue:@"Hello world !" forKey:@"myVariable"]; NSURLConnection *theConnection=[[NSURLConnection alloc] initWithRequest:request delegate:self]; if (theConnection) { receiveData = [NSMutableData data]; } […]

UIWebView将不会加载带有证书的链接(https://前缀)

我知道这已经被问过,但我已经看过每个答案(没有太多),没有人帮助我。 我遇到的问题是用我学校的电子邮件服务处理证书。 这两个电子邮件服务的链接在这里: 主要学校电子邮件: https : //marauder.millersville.edu/mail/index.pl 计算机科学电子邮件: https : //cs.millersville.edu/cswebmail 大学学生门户(在我的UIWebView中单击时,右侧的Marauder Mailbutton不会打开) http://myville.millersville.edu/ 起初,这两个网站都不会使用标准的NSURL和NSURLRequest加载到我的UIWebView中。 我查看networking上的解决scheme,并有人build议使用NSURLProtocolClient委托方法。 在实现它们之后,我的UIWebView现在会加载学校的邮件电子邮件只有当我点击一个button,直接打开链接,而不是尝试从门户网站访问邮件(上面的第三个链接),它仍然从不加载计算机科学电子邮件链接。 我已经search了iOS帮助网站,发布了问题,尝试了多个开放源代码的自定义UIWebViews,但是我还没有find任何可行的方法。 我在网上阅读的大多数答案指向ASIHTTPRequest。 我试过这个,但我不能实现它的权利,它不会加载我的UIWebView中的链接; 这里是我如何加载链接的代码: mURL = [self getURL:viewNumber]; ASIHTTPRequest *req = [ASIHTTPRequest requestWithURL:mURL]; [req setDelegate:self]; [req startSynchronous]; //NSURLRequest *req = [NSURLRequest requestWithURL:mURL]; //urlConnection=[[NSURLConnection alloc] initWithRequest:req delegate:self]; webView.scalesPageToFit = YES; //[webView loadRequest:req]; 代码中的注释是我如何加载一个没有ASIHTTPRequest的链接。 任何帮助表示赞赏! 另外,我有我的UIWebView的另一个问题,链接如下。 我没有任何答案,所以如果你感到无聊,请检查: UIWebView不检测网站上的文本框

用UIWebView loadRequest发送自定义标题

我想能够发送一些额外的头与我的UIWebView loadRequest方法。 我努力了: NSMutableURLRequest *req = [NSMutableURLRequest requestWithURL:[NSURL URLWithString:@"http://www.reliply.org/tools/requestheaders.php"]]; [req addValue:@"hello" forHTTPHeaderField:@"aHeader"]; [self.theWebView loadRequest:req]; 我也尝试了UIWebView子类并截取- (BOOL)webView:(UIWebView *)webView shouldStartLoadWithRequest:(NSURLRequest *)request navigationType:(UIWebViewNavigationType)navigationType方法。 在这个方法中,我有一个代码块,看起来像这样: NSMutableURLRequest *newRequest = [request mutableCopy]; for(NSString *key in [customHeaders allKeys]) { [newRequest setValue:[customHeaders valueForKey:key] forHTTPHeaderField:key]; } [self loadRequest:newRequest]; 但由于一些未知的原因,它导致网页视图不加载任何东西(空白帧)和错误消息NSURLErrorCancelled (-999)出现(所有已知的修补程序不能解决这个问题)。 所以我不知道该怎么做。 我怎样才能发送一个自定义标题与一个UIWebView请求? 非常感谢!

有没有办法将参数的NSDictionary附加到NSURLRequest而不是手动创build一个string?

AFNetworking允许你添加一个参数的NSDictionary到一个请求,并将它附加到请求。 所以,如果我想要做一个GET请求?q=8&home=8888我只是简单地做一个NSDictionary,比如@{@"q": @"8", @"home": @"8888"} 。 有没有办法做到NSURLSession / NSURLConnection / NSURLRequest ? 我知道我可以使用NSJSONSerialization来附加JSON数据,但是如果我只是希望它们作为GET参数在URL中呢? 我应该只是添加一个类别?

NSURLErrorDomain错误-1012

我需要parsing密码保护的URL的XML文件我试着下面 NSURLCredential *credential = [NSURLCredential credentialWithUser:@"admin" password:@"123456" persistence:NSURLCredentialPersistenceForSession]; NSURLProtectionSpace *protectionSpace = [[NSURLProtectionSpace alloc] initWithHost:@"xyz.com" port:80 protocol:@"http" realm:nil authenticationMethod:NSURLAuthenticationMethodDefault]; [[NSURLCredentialStorage sharedCredentialStorage] setCredential:credential forProtectionSpace:protectionSpace]; url = [NSURL URLWithString:urlString]; NSMutableURLRequest *request = [NSMutableURLRequest requestWithURL:url]; [request setHTTPMethod:@"GET"]; [request setValue:@"application/xml" forHTTPHeaderField:@"Content-Type"]; connection = [[NSURLConnection alloc] initWithRequest:request delegate:self]; NSURLResponse *response; NSError *error; NSData *returnData = [NSURLConnection sendSynchronousRequest:request returningResponse: &response error: &error]; […]

从iOS发送多部分POST并读取PHP $ _POST中的参数?

我试图从iPhone / iPad发送一个多行文章到一个PHP服务,问题是,由于某种原因,POST内容types似乎是应用程序/ x-www-form-urlenconded,(我发现这个使用Wireshark) 这实际上是Wireshark POST数据包捕获的一个片段: **Content-Type: application/x-www-form-urlencoded\r\n** Content-Length: 324\r\n [Content length: 324] Connection: keep-alive\r\n \r\n [Full request URI: http://my.server.com/mobile/tools/authentication] Line-based text data: application/x-www-form-urlencoded –0xKhTmLbOuNdArY\r\n Content-Disposition: form-data; name="login"\r\n \r\n hello@hello.com\r\n –0xKhTmLbOuNdArY\r\n Content-Disposition: form-data; name="password"\r\n \r\n somepassword\r\n –0xKhTmLbOuNdArY\r\n \r\n –0xKhTmLbOuNdArY–\r\n 问题是,在服务器我试图从这个POST请求读取login和密码variables,但这是不可能的,因为我认为php认为POST请求是x-www-form-urlencoded ,所以如果我设置authentication.php来做: <?php echo("<pre>") print_r($_POST) echo("</pre>") ?> 我得到这个: <pre>Array\n (\n [–0xKhTmLbOuNdArY\r\n Content-Disposition:_form-data;_name] => "login"\r\n \r\n hello@hello.com\r\n […]

我如何在Swift中设置UIWebView的“User-Agent”标题

我正在使用Swift的iOS应用程序的Xcode 6。 我有一个embedded式UIWebView的简单的ViewController。 你可以find下面的代码。 现在我想更改User-Agent HTTP标头。 我试图使用NSURLRequest的setValue方法,但它不起作用(请参阅未注释的行)。 有谁知道这是怎么做到的吗? import UIKit class WebViewController: UIViewController { @IBOutlet weak var webView: UIWebView! override func viewDidAppear(animated: Bool) { var url = NSURL(string: "https://www.samplepage.com") var request = NSMutableURLRequest(URL: url) // request.setValue("Custom-Agent", forHTTPHeaderField: "User-Agent") webView.loadRequest(request) } }