Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #import "ViewController.h"
- @interface ViewController ()
- @end
- @implementation ViewController
- - (void)viewDidLoad {
- [super viewDidLoad];
- // - category_id, type: integer
- // - option, type: string("all_word", "learned" or "no_learn")
- // - page, type: integer, numericality: {greater_than: 0}, optional
- // - per_page, type: integer, optional, default: 10
- // - auth_token, type: string, presence: true
- // NSString *post = [NSString stringWithFormat:@""];
- // //@"category_id=%d&option=%@page=%d&per_page=%d&auth_token=%@",15,@"all_word",1,1,@"sRT915Jqr8A2bg1v0m-MHg"];
- // NSData *postData = [post dataUsingEncoding:NSASCIIStringEncoding allowLossyConversion:YES];
- // NSString *postLength = [NSString stringWithFormat:@"%d",[postData length]];
- //
- NSMutableURLRequest *request = [[NSMutableURLRequest alloc] init];
- [request setURL:[NSURL URLWithString:[NSString stringWithFormat:@"https://manh-nt.herokuapp.com/words.json?category_id=15&option=all_word&page=1&per_page=1&auth_token=sRT915Jqr8A2bg1v0m-MHg"]]];
- [request setHTTPMethod:@"GET"];
- // [request setValue:postLength forHTTPHeaderField:@"Content-Length"];
- [request setValue:@"application/x-www-form-urlencoded" forHTTPHeaderField:@"Current-Type"];
- // [request setHTTPBody:postData];
- NSURLConnection *conn = [[NSURLConnection alloc]initWithRequest:request delegate:self];
- if(conn)
- {
- NSLog(@"Connection Successful");
- }
- else
- {
- NSLog(@"Connection could not be made");
- }
- }
- // This method is used to receive the data which we get using post method.
- - (void)connection:(NSURLConnection *)connection didReceiveData:(NSData*)data {
- NSLog(@"didReceiveData");
- NSString* myString;
- myString = [[NSString alloc] initWithData:data encoding:NSASCIIStringEncoding];
- NSLog(@"%@",myString);
- }
- // This method receives the error report in case of connection is not made to server.
- - (void)connection:(NSURLConnection *)connection didFailWithError:(NSError *)error {
- NSLog(@"error");
- }
- // This method is used to process the data after connection has made successfully.
- - (void)connectionDidFinishLoading:(NSURLConnection *)connection {
- NSLog(@"connectionDidFinishLoading");
- }
- - (IBAction)signinClicked:(id)sender {
- }
- - (IBAction)TurnOffKeyboard:(id)sender {
- [self.view endEditing:YES];
- }
- -(BOOL) textFieldShouldReturn:(UITextField *)textField {
- [textField resignFirstResponder];
- return YES;
- }
- @end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement