0

我有以下用于将数据发布到 Web 服务器的代码,但它给了我空响应,我有多个数据,它们是:-

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], 

我必须发布这些数据,并且我使用此代码进行发布,但它对我不起作用。请帮帮我。

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)

提前致谢。

4

2 回答 2

0

这是一篇演示如何使用 iOS 应用程序使用 .NET Web 服务的文章。您可以使用文章中讨论的技术:

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

于 2012-05-22T21:57:30.183 回答
0

我所做的几乎所有工作都涉及 .NET 和 iOS。在这里查看我一直编写和使用的网络类(基于 AFNetworking)。我更喜欢使用常规的 aspx 表单而不是 asmx 网络服务。我这样做是因为我不想将任何网络方法暴露给窥探的访问者,并且在以 aspx 形式返回任何内容之前,我会使用 API 密钥检查。如果您需要,我可以向您发送一个示例 .NET 代码(用 VB.NET 编写)。

于 2012-05-23T00:10:19.573 回答