2

I have some parameters to send post request to the server:

`[{"LoginID":151,"UserID":0,"SubUserID":0,"WorkGroupID":92,"WorksFor":"Doctor","UserWorkGroup":0},{"SearchingFilters":{"GroupingOperator":"And","Filters":[{"SearchingValue":"04-13-2016","SearchingName":"AppointmentDate","SearchingOperator":"Ge"},{"SearchingValue":"04-27-2016","SearchingName":"AppointmentDate","SearchingOperator":"Le"}],"Groups":[{"Groups":[],"GroupingOperator":"And","Filters":[]}]},"Searching":true,"SortingOrder":"Desc","RecordsCount":10,"PageIndex":0}]` 

How to send like in this format?

[getProfileServices sendSynchronousPostRequestWithStringForAction:getProfileURL andParameters:[[NSDictionary alloc] initWithObjectsAndKeys:[[NSUserDefaults standardUserDefaults] objectForKey:@"USER_ID"],@"LoginID",@"0",@"UserID",@"0",@"SubUserID",[[NSUserDefaults standardUserDefaults] objectForKey:@"WORK_ID"],@"WorkGroupID",@"Doctor",@"WorksFor",@"0",@"UserWorkGroup",nil] andRequestType:@"POST"]; 

2 Answers 2

1

First you need to sent request using json format not direct as object

And Second

I think there is requires to change in service

Service should accept your request in this format.

{ "LoginID": 151, "UserID": 0, "SubUserID": 0, "WorkGroupID": 92, "WorksFor": "Doctor", "UserWorkGroup": 0, "SearchingFilters": { "GroupingOperator": "And", "Filters": [ { "SearchingValue": "04-13-2016", "SearchingName": "AppointmentDate", "SearchingOperator": "Ge" }, { "SearchingValue": "04-27-2016", "SearchingName": "AppointmentDate", "SearchingOperator": "Le" } ], "Groups": [ { "Groups": [ ], "GroupingOperator": "And", "Filters": [ ] } ] }, "Searching": true, "SortingOrder": "Desc", "RecordsCount": 10, "PageIndex": 0 } 

If you required to pass it as single object else add this in array if multiple object is send in request

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

Comments

1

@Raghvendra first of set your parameter in dictionary for passing parameter and then set your url
enter code here

-(void)call_WebService { NSMutableDictionary *dicParameter=[[NSMutableDictionary alloc] init]; [dicParameter setObject:@"" forKey:@"Parameter1"];// setObject - String/Dictionary/Array [dicParameter setObject:@"" forKey:@"parameter2"]; // setObject - String/Dictionary/Array [dicParameter setObject:@"" forKey:@"Parameter3"];// setObject - String/Dictionary/Array NSError *error = nil; NSData *data = [NSJSONSerialization dataWithJSONObject: dicParameter options:0 error:&error]; NSString *string = [[NSString alloc] initWithData:data encoding:NSUTF8StringEncoding]; if (error) NSLog(@"%s: JSON encode error: %@", __FUNCTION__, error); NSURL *url = [NSURL URLWithString:@"web Service url url"]; NSMutableURLRequest *request = [NSMutableURLRequest requestWithURL:url]; [request setHTTPMethod:@"POST"]; NSString *params = [NSString stringWithFormat:@"json=%@", [string stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding]]; NSData *paramsData = [params dataUsingEncoding:NSUTF8StringEncoding]; [request addValue:@"8bit" forHTTPHeaderField:@"Content-Transfer-Encoding"]; [request addValue:@"application/x-www-form-urlencoded" forHTTPHeaderField:@"Content-Type"]; [request setHTTPBody:paramsData]; NSURLResponse *response = nil; NSData *returnData = [NSURLConnection sendSynchronousRequest:request returningResponse:&response error:&error]; if (error) NSLog(@"%s: NSURLConnection error: %@", __FUNCTION__, error); // examine the response NSString *responseString = [[NSString alloc] initWithData:returnData encoding:NSUTF8StringEncoding]; NSLog(@"responseString: %@",responseString); if(![responseString isEqualToString:@""]) { NSDictionary *dicFinalGetFacility = [NSJSONSerialization JSONObjectWithData:returnData options:kNilOptions error:&error]; NSLog(@"dicFinalGetFacility: %@",dicFinalGetFacility); } } 

3 Comments

[{ "LoginID":151, "UserID":0, "SubUserID":0, "WorkGroupID":92, "WorksFor":"Doctor", "UserWorkGroup":0 }, { "SearchingFilters":{ "GroupingOperator":"And", "Filters":[ { "SearchingValue":"04-13-2016", "SearchingName":"AppointmentDate", "SearchingOperator":"Ge" }, { "SearchingValue":"04-27-2016", "SearchingName":"AppointmentDate", "SearchingOperator":"Le" } ], "Groups":[ { "Groups":[ ], "GroupingOperator":"And", "Filters":[ ] } ] }, "Searching":true, "SortingOrder":"Desc", "RecordsCount":10, "PageIndex":0 } ]
like this [getProfileServices sendSynchronousPostRequestWithStringForAction:getProfileURL andParameters:[[NSDictionary alloc] initWithObjectsAndKeys:[[NSUserDefaults standardUserDefaults] objectForKey:@"USER_ID"],@"LoginID",@"0",@"SubUserID",[[NSUserDefaults standardUserDefaults] objectForKey:@"WORK_ID"],@"WorkGroupID",@"Doctor",@"WorksFor",@"0",@"UserWorkGroup",nil] andRequestType:@"POST"];
@RaghavenderReddy plz read code carefully and tell me, if you have any query, - in this code your whole array set in dicParameter first object then give it parameter name and just put your url and also take care about parameter you will assign to your whole array it give to backend side for parsing..

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.