nsurlconnection

iPhone sending POST with NSURLConnection

醉酒当歌 提交于 2019-11-26 07:27:38
问题 I\'m having some problems with sending POST data to a PHP script with NSURLConnection. This is my code: const char *bytes = [[NSString stringWithFormat:@\"<?xml version=\\\"1.0\\\"?>\\n<mydata>%@</mydata>\", data] UTF8String]; NSURL *url = [NSURL URLWithString:@\"http://myurl.com/script.php\"]; NSMutableURLRequest *request = [NSMutableURLRequest requestWithURL:url]; [request setHTTPMethod:@\"POST\"]; [request setHTTPBody:[NSData dataWithBytes:bytes length:strlen(bytes)]]; NSURLResponse

Changing the userAgent of NSURLConnection

天涯浪子 提交于 2019-11-26 07:25:41
问题 Hey I am using a NSURL Connection to receive data. [NSURLConnection sendSynchronousRequest: //create request from url [NSURLRequest requestWithURL: //create url from string [NSURL URLWithString:url] ] //request parameters returningResponse:nil error:nil ] Is it possible to change the user agent string? right now it is: AppName/AppVersion CFNetwork/459 Darwin/10.0.0.d3 回答1: Obj-C: NSString* userAgent = @"My Cool User Agent"; NSURL* url = [NSURL URLWithString:@"http://whatsmyuseragent.com/"];

how to use sendAsynchronousRequest:queue:completionHandler:

泪湿孤枕 提交于 2019-11-26 06:58:39
问题 Two part question Part one: I am trying to create an ASynchronous request to my database. I am currently doing it Synchronously however I want to learn both ways to better my understanding of whats going on. Currently I have set up my Synchronous call like this. - (IBAction)setRequestString:(NSString *)string { //Set database address NSMutableString *databaseURL = [[NSMutableString alloc] initWithString:@\"http://127.0.0.1:8778/instacodeData/\"]; // imac development //PHP file name is being

How to make an progress bar for an NSURLConnection when downloading a file?

偶尔善良 提交于 2019-11-26 04:39:38
问题 I want to show up an progress bar while a download with NSURLConnection is happening. As I am getting data from the server, I could update the UI for every received package. But the problem is: How do I figure out how much data I have already, and how much data has to be downloaded? Probably in bytes... And then I have to do some math to get the percentage? 回答1: In your NSURLConnection delegate, implement something like this to find out the total content length. The server has to support this

NSURLConnection Using iOS Swift

北城以北 提交于 2019-11-26 04:04:38
问题 I am trying to follow this tutorial and connect to a JSON api using Swift and NSURLConnection . I can see that it is hitting the url but the connectionDidFinishLoading does not seem to fire. import UIKit class Remote: NSObject { var host = \"http://localhost:3000\" var query = String() var data: NSMutableData = NSMutableData() func connect(query:NSString) { self.query = query var url = self.document() var conn = NSURLConnection(request: url, delegate: self, startImmediately: true) } func

NSURLConnection timeout?

允我心安 提交于 2019-11-26 02:52:58
问题 I\'m using this NSURLConnection with delegates. nsconnection = [[NSURLConnection alloc] initWithRequest:request delegate:self startImmediately:YES]; Problem is the website doesn\'t respond at all. Nothing, just spins in browser with blank page, no failure. In my delegates, I handle the failure, but when the site doesn\'t respond the delegates don\'t get called. Any ideas on how to timeout the connection? 回答1: You can specify a timeout in your NSURLRequest object. One way to do this is to

NSURLConnection and Basic HTTP Authentication in iOS

我的梦境 提交于 2019-11-26 02:28:29
问题 I need to invoke an initial GET HTTP request with Basic Authentication . This would be the first time the request is sent to the server and I already have the username & password so there\'s no need for a challenge from the server for authorization. First question: Does NSURLConnection have to be set as synchronous to do Basic Auth? According to the answer on this post, it seems that you can\'t do Basic Auth if you opt for the async route. Anyone know of any some sample code that illustrates

Sending an HTTP POST request on iOS

那年仲夏 提交于 2019-11-26 01:26:22
问题 I\'m trying to send an HTTP Post with the iOS application that I\'m developing but the push never reaches the server although I do get a code 200 as response (from the urlconnection). I never get a response from the server nor does the server detect my posts (the server does detect posts coming from android) I do use ARC but have set pd and urlConnection as strong. This is my code for sending the request NSMutableURLRequest *request = [[NSMutableURLRequest alloc] initWithURL:[NSURL

Easiest way to detect Internet connection on iOS?

一笑奈何 提交于 2019-11-26 00:50:01
问题 I know this question will appear to be a dupe of many others, however, I don\'t feel the simple case is well explained here. Coming from an Android and BlackBerry background, making requests through HTTPUrlConnection instantly fail if there is no connection available. This seems like completely sane behavior, and I was surprised to find NSURLConnection in iOS did not emulate it. I understand that Apple (and others who have extended it) provide a Reachability class to assist with determining

The resource could not be loaded because the App Transport Security policy requires the use of a secure connection

点点圈 提交于 2019-11-26 00:18:44
问题 I am facing the Problem when I have updated my Xcode to 7.0 or iOS 9.0. Somehow it started giving me the Titled error \"The resource could not be loaded because the App Transport Security policy requires the use of a secure connection\" Webservice Method: -(void)ServiceCall:(NSString*)ServiceName :(NSString *)DataString { NSURLSessionConfiguration *sessionConfiguration = [NSURLSessionConfiguration defaultSessionConfiguration]; [sessionConfiguration setAllowsCellularAccess:YES];