0

I have a url , and two parameters to pass before making request. What I am doing is appending values of all the url, parameterA, and parameterB.

NSString*urlString=@"www.example.com";
NSString*paramA=@"day=20140715";
NSString*paramA=@"mode=2ndMode";
   NSArray *URLArray = [[NSArray alloc] initWithObjects:urlString,paramA,paramB, nil];
        NSString *helloString = [URLArray componentsJoinedByString:@""];
 NSData *dataA = [NSData dataWithContentsOfURL:helloString];
 NSString *responseSt = [[NSString alloc] initWithData:dataA encoding:NSUTF8StringEncoding];

NOW THIS IS EASY WAY DOING A CONNECTION, BUT HOW DO WE WRITE A METHOD FOR URL REQUEST IN A PROPER WAY? Something that returns string after the request is complete.

-(void)url(NSString*)helloString ParameterA(NSString*)paramA ParameterB(NSString*)paramB ??
2
  • You will get response object from your server, if you want to return a string then return a string from server, it totally depends on you what you want to return after calling a request to server. Commented Jul 15, 2014 at 12:12
  • I want to write a request for example -(void)url(NSString*)helloString ParameterA(NSString*)paramA ParameterB(NSString*)paramB Commented Jul 15, 2014 at 12:15

1 Answer 1

2
NSString*url = @"www.example.com";
NSString*paramA = @"day=20140715";
NSString*paramB = @"mode=2ndMode";
NSArray *params = [[NSArray alloc] initWithObjects:paramA,paramB, nil];
NSString *URLStr = [params componentsJoinedByString:@"&"];
URLStr = [url stringByAppendingFormat:@"?%@",URLStr];
NSData *dataA = [NSData dataWithContentsOfURL:[NSURL URLWithString:URLStr]];
NSString *responseSt = [[NSString alloc] initWithData:dataA encoding:NSUTF8StringEncoding];

Try this code.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.