0

I have below code for posting data to the web server but it gives me null response, I have multiple data and they are:-

date,
 rig,
 driller,
 offsider-1,
 offsider-2,
 shift
,
project,
supervisoremail,
geologistemail,

comments,


plants[0][name-id],
plants[0][start-usage],
plants[0][end-usage],

consumables[0][category],
consumables[0][name-id],
consumables[0][used],
consumables[0][code],
consumables[0][description], 

I have to post this data and I used this code for posting but it didn't work for me. Please help me out.

NSURL *url=[NSURL URLWithString:@"http://www.mydor.com.au/staff/dor/idorInsert"];
    NSString *post =[[NSString alloc]initWithFormat:@"date=15/08/2012&rig=53&driller=207&offsider-1=131&offsider- 2=236&shift=day&project=24&supervisoremail=24&geologistemail=24&comments=&plants[0][name- id]=286&plants[0][start-usage]=1.0&plants[0][end-usage]=0.0"];
    NSLog(post);
    NSData *postData = [post dataUsingEncoding:NSASCIIStringEncoding allowLossyConversion:YES];

    NSString *postLength = [NSString stringWithFormat:@"%d", [postData length]];

    NSMutableURLRequest *request = [[[NSMutableURLRequest alloc] init] autorelease];
    [request setURL:url];
    [request setHTTPMethod:@"POST"];
    [request setValue:postLength forHTTPHeaderField:@"Content-Length"];
    [request setValue:@"application/x-www-form-urlencoded" forHTTPHeaderField:@"Content-Type"];
    [request setHTTPBody:postData];
    [NSURLRequest setAllowsAnyHTTPSCertificate:YES forHost:[url host]];

    NSError *error;
    NSURLResponse *response;
    NSData *urlData=[NSURLConnection sendSynchronousRequest:request returningResponse:&response error:&error];
    NSLog(@"here u re");
    NSString *data=[[NSString alloc]initWithData:urlData encoding:NSUTF8StringEncoding];
    NSLog(@"here also called");
    NSLog(@"%@",data)

Thanks in advance.

Jprat
  • 39
  • 8
  • Are you sure that your "post" string is really the body? It looks more like a query string that should be appended to the URL. – sc0rp10n May 22 '12 at 21:44
  • Hi, I don't know, I just used it by referencing from other web site it work for me login web service and i use string username=xx&password=xyz and it works. For it i don't know how to implement data – Jprat May 22 '12 at 22:06

2 Answers2

0

Here is an article which demonstrates how to consume .NET Web service using iOS application. You can use the techniques discussed in the article:

http://www.highoncoding.com/Articles/809_Consuming__NET_Web_Services_in_an_iOS_Application.aspx

azamsharp
  • 19,710
  • 36
  • 144
  • 222
0

Almost all the work I do involves .NET with iOS. Have a look here for the network class I wrote and use all the time (AFNetworking based). I prefer to use a regular aspx form instead of an asmx web-service. I do this because I don't want to expose any web-methods to snooping visitors and I use an API key check before returning anything in the aspx form. I can send you an example .NET code (written in VB.NET) if you need me to.

Community
  • 1
  • 1
LJ Wilson
  • 14,445
  • 5
  • 38
  • 62
  • Can you tell me which method is appropriate for me from your suggested methods and can I use my code which i posted with little changes or I have to made changes at your way.Please tell me what is wrong in my method, am I sending data in wrong way or where is the fault. Please guide. Thank You. – Jprat May 23 '12 at 00:21
  • The network class I referred to would be used instead of NSMutableURLRequest and NSURLConnection. The methods in the network class are pretty self-explanatory. – LJ Wilson May 23 '12 at 00:32