Currently i am facing an issue like :: I have an some parameters like (UserName=Brahmam&Passowrd=123&Mobileno=98989898&emailid=Brahmam@gmail.com) and already my .net developer created API using ( C# with response is JSON format only).
Here I uploaded my source code:
-(void)registestion{
NSString * apiURLStr =[NSString stringWithFormat:@"http://example.com/api/v1/example?UserName=Brahmam&Passowrd=123&Mobileno=98989898&emailid=Brahmam@gmail.com"];
NSMutableURLRequest *dataRqst = [NSMutableURLRequest requestWithURL:[NSURL URLWithString:apiURLStr] cachePolicy:NSURLRequestUseProtocolCachePolicy timeoutInterval:30.0];
[dataRqst setHTTPMethod:@"POST"];
NSString *stringBoundary = @"0xKhTmLbOuNdArY---This_Is_ThE_BoUnDaRyy---pqo";
NSString *headerBoundary = [NSString stringWithFormat:@"multipart/form-data; boundary=%@",stringBoundary];
[dataRqst addValue:headerBoundary forHTTPHeaderField:@"Content-Type"];
NSMutableData *postBody = [NSMutableData data];
[dataRqst setHTTPBody:postBody];
NSHTTPURLResponse *response =[[NSHTTPURLResponse alloc] init];
NSError* error;
NSData *responseData = [NSURLConnection sendSynchronousRequest:dataRqst returningResponse:&response error:&error];
NSString *responseString = [[NSString alloc] initWithBytes:[responseData bytes] length:[responseData length] encoding:NSUTF8StringEncoding];
NSLog(@"%@",responseString);
}
If i run this API usin Browser : the response is
But i am unable to post date from objective-c to C# web service:: I tried to use above code but i am getting response like:
Can any one help me out Plz..
Use the below matter
NSString * apiURLStr =[NSString stringWithFormat:@"http://taxi.expertverification.com/api/v1/RegistrationAPI?UserName=Brahmam&Passowrd=123&Mobileno=98989898&emailid=Brahmam123444@gmail.com"];
NSMutableURLRequest *dataRqst = [NSMutableURLRequest requestWithURL:[NSURL URLWithString:apiURLStr] cachePolicy:NSURLRequestUseProtocolCachePolicy timeoutInterval:30.0];
NSHTTPURLResponse *response =[[NSHTTPURLResponse alloc] init];
NSError* error = [[NSError alloc] init] ;
NSData *responseData = [NSURLConnection sendSynchronousRequest:dataRqst returningResponse:&response error:&error];
NSString *responseString = [[NSString alloc] initWithBytes:[responseData bytes] length:[responseData length] encoding:NSUTF8StringEncoding];
NSLog(@"%@",responseString);
NSURL *main_Url = [NSURL URLWithString:baseUrl];
NSURLSessionConfiguration *config = [NSURLSessionConfiguration defaultSessionConfiguration];
NSURLSession *session = [NSURLSession sessionWithConfiguration:config];
NSMutableURLRequest *request = [[NSMutableURLRequest alloc] initWithURL:main_Url];
[request addValue:@"application/json" forHTTPHeaderField:@"Content-Type"];
request.HTTPMethod = @"POST";
NSError *error = nil;
NSData *Postdata = [NSJSONSerialization dataWithJSONObject:dictParameter options:0 error:&error];
if (!error) {
NSURLSessionUploadTask *uploadTask = [session uploadTaskWithRequest:request
fromData:Postdata completionHandler:^(NSData *Pdata,NSURLResponse *response,NSError *error) {
if(!error) {
_onSuccess(Pdata);
} else{
_onError(error);
}
}];
[uploadTask setTaskDescription:@"DatPasted"];
[uploadTask resume];
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.