I am trying to send data to the server.When i am sending the request it send to the server but server get its blank.I am not getting why it is happend.Please help me to solve this.
NSArray *keys = [NSArray arrayWithObjects:@"username",@"password",@"email",@"fullname",@"phone",@"status",nil];
NSArray *objects = [NSArray arrayWithObjects:@"test",@"123456",@"test999@test.com",@"name",@"234566343",@"1",nil];
NSDictionary *questionDict = [NSDictionary dictionaryWithObjects:objects forKeys:keys];
NSDictionary *jsonDict = [NSDictionary dictionaryWithDictionary:questionDict];
NSString *jsonRequest = [jsonDict JSONRepresentation];
RequestHandler *handler = [[RequestHandler alloc] init];
handler.method = @"POST";
handler.delegate = self;
NSLog(@"JSOnRequest -- %@",jsonRequest);
handler.postData = jsonRequest;
handler.requestName = @"registration";
handler.URL =@"http://demo.keshavinfotech.com/edv/user_register.php?";
[handler startRequest];
[handler release];
- (void)startRequest
{
NSURL *requestURL = [NSURL URLWithString:[NSString stringWithFormat:@"%@",mRequestURL]];//NSURLRequestReturnCacheDataElseLoad
NSMutableURLRequest* request = [NSMutableURLRequest requestWithURL:requestURL
cachePolicy:NSURLRequestReturnCacheDataElseLoad
timeoutInterval:mTimeOut];
[request setHTTPMethod:@"POST"];
[request setValue:@"application/json" forHTTPHeaderField:@"Accept"];
[request setValue:@"application/json" forHTTPHeaderField:@"Content-Type"];
[request setValue:[NSString stringWithFormat:@"%d", [mPostData length]] forHTTPHeaderField:@"Content-Length"];
[request setHTTPBody:[mPostData dataUsingEncoding:NSUTF8StringEncoding]];
self.connection = [[[NSURLConnection alloc]initWithRequest:request delegate:self] autorelease];
}
is it server encoding-decoding problem or something else???
I call to server with following parameters,
WebserviceCall[622:f803] {
email = "test999@test.com";
fullname = name;
password = 123456;
phone = 234566343;
status = 1;
username = test;
}
Then Response give to me like following wise.
{"responseData":{"result":"failed","msg":"Please fill all the required fields"}}
Can you pls give the right parameter format to send with that i can check it out.
Try doing like this:
//form you request like you did (I think it's ok), then
NSData *postData = jsonRequest;
NSString *postLength = [NSString stringWithFormat:@"%d", [postData length]];
NSMutableURLRequest *urlRequest = [[[NSMutableURLRequest alloc] init] autorelease];
[urlRequest setURL:@"http://demo.keshavinfotech.com/edv/user_register.php?"];
[urlRequest setHTTPMethod:@"POST"];
[urlRequest setValue:postLength forHTTPHeaderField:@"Content-Length"];
[urlRequest setValue:@"application/x-www-form-urlencoded" forHTTPHeaderField:@"Content-Type"];
[urlRequest setValue:@"utf-8" forHTTPHeaderField:@"charset"];
[urlRequest setHTTPBody:postData];
[urlRequest setTimeoutInterval:60.0];//or whatever interval you prefer
NSURLConnection *tmpConn = [[[NSURLConnection alloc] initWithRequest:urlRequest delegate:self] autorelease];
self.connectionProperty = tmpConn;
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.