---
title: "How to send HTTP Request in iOS using NSURLConnection Objective-C"  
description: "How to send HTTP Request in iOS using NSURLConnection Objective-C"  
author: "Samuel Fernandes"  
published: 2017-01-12  
updated: 2017-01-12  
canonical: https://www.mindstick.com/forum/34241/how-to-send-http-request-in-ios-using-nsurlconnection-objective-c  
category: "ios"  
tags: ["ios", "objective c"]  
reading_time: 1 minute  

---

# How to send HTTP Request in iOS using NSURLConnection Objective-C

Hi Buddy\
I am new in iOS .I want to [register](https://www.mindstick.com/blog/220/registering-client-script-in-asp-dot-net) [user](https://www.mindstick.com/articles/13001/multi-statement-table-valued-user-defined-function-in-sql-server) through [iOS app](https://www.mindstick.com/forum/160260/what-is-the-best-place-to-hire-an-ios-app-developer) I have PHP webpage for [registration process](https://www.mindstick.com/forum/160224/how-to-customize-the-user-registration-process-in-asp-dot-net-core-identity) .I want send [json data](https://www.mindstick.com/forum/782/how-to-send-request-amp-amp-response-from-json-data-using-asp-dot-net) on my [web page](https://www.mindstick.com/forum/718/sql-server-report-alignment-to-center-of-web-page) . How to send HTTP Request in iOS using NSURLConnection Objective-C .Please help I would really appreciate your help.\
Thanks\

## Replies

### Reply by Sunil Singh

Following is the Objective-C code to post json [data](https://www.mindstick.com/articles/13050/salesforce-aiming-to-dominate-predictive-analytics-with-data-science) in iOS -

\

```
NSMutableDictionary *requestDictionary = [[NSMutableDictionary alloc]
init];[requestDictionary setObject:@"Robert" forKey:@"firstName"];[requestDictionary setObject:@"Abraham" forKey:@"lastName"];[requestDictionary setObject:@"robertab1999@gmail.com" forKey:@"email"];[requestDictionary setObject:@"pass1234" forKey:@"password"];NSData *data = [NSJSONSerialization dataWithJSONObject:requestDictionary
options:NSJSONWritingPrettyPrinted
error:nil];NSString *jsonStr = [[NSString alloc]
initWithData:data encoding:NSUTF8StringEncoding];NSURL *url = [NSURL URLWithString:@"http://192.168.1.51:82/test/handleRequest.php"];NSMutableURLRequest *request = [NSMutableURLRequest requestWithURL:urlcachePolicy:NSURLRequestUseProtocolCachePolicy
timeoutInterval:60.0];[request setHTTPMethod:@"POST"];[request setValue:@"application/json"
forHTTPHeaderField:@"Accept"];[request setValue:@"application/json"
forHTTPHeaderField:@"Content-Type"];[request setValue:[NSString stringWithFormat:@"%lu",(unsigned long)jsonStr.length]
forHTTPHeaderField:@"Content-Length"];[request setHTTPBody: data];NSHTTPURLResponse* response =[[NSHTTPURLResponse alloc]init];NSError*error = [[NSError alloc] init];//synchronous
filling of data from HTTP POST response NSData
*responseData = [NSURLConnection sendSynchronousRequest:request returningResponse:&response
error:&error];//convert
data into string NSString*responseString = [[NSString alloc] initWithBytes:[responseData
bytes]
length:[responseData length]
encoding:NSUTF8StringEncoding];NSLog(@"Response code %ld",(long)[response statusCode]);NSLog(@"Response String %@",responseString);
```


---

Original Source: https://www.mindstick.com/forum/34241/how-to-send-http-request-in-ios-using-nsurlconnection-objective-c

Copyright © MindStick Software Pvt. Ltd. This Markdown version is provided for developers, AI systems, and offline reading.
