Append data to a POST NSURLRequest

If you don’t wish to use 3rd party classes then the following is how you set the post body… NSURL *aUrl = [NSURL URLWithString:@”http://www.apple.com/”]; NSMutableURLRequest *request = [NSMutableURLRequest requestWithURL:aUrl cachePolicy:NSURLRequestUseProtocolCachePolicy timeoutInterval:60.0]; [request setHTTPMethod:@”POST”]; NSString *postString = @”company=Locassa&quality=AWESOME!”; [request setHTTPBody:[postString dataUsingEncoding:NSUTF8StringEncoding]]; NSURLConnection *connection= [[NSURLConnection alloc] initWithRequest:request delegate:self]; Simply append your key/value pair to the post string

Swift GET request with parameters

When building a GET request, there is no body to the request, but rather everything goes on the URL. To build a URL (and properly percent escaping it), you can also use URLComponents. var url = URLComponents(string: “https://www.google.com/search/”)! url.queryItems = [ URLQueryItem(name: “q”, value: “War & Peace”) ] The only trick is that most web … Read more

How to send json data in the Http request using NSURLRequest

Here’s what I do (please note that the JSON going to my server needs to be a dictionary with one value (another dictionary) for key = question..i.e. {:question => { dictionary } } ): NSArray *objects = [NSArray arrayWithObjects:[[NSUserDefaults standardUserDefaults]valueForKey:@”StoreNickName”], [[UIDevice currentDevice] uniqueIdentifier], [dict objectForKey:@”user_question”], nil]; NSArray *keys = [NSArray arrayWithObjects:@”nick_name”, @”UDID”, @”user_question”, nil]; NSDictionary … Read more