【问题标题】:POST JSON data from iOS to mssql Server [closed]POST JSON 数据从 iOS 到 mssql 服务器 [关闭]
【发布时间】:2013-12-11 13:48:40
【问题描述】:

谁能告诉我创建将 JSON 发送到 MS SQL 服务器的 Web 服务的最佳方法是什么。(php 或 .net POST Web 服务?) 如果可能的话,我想在 IIS 上托管 Web 服务。教程的链接将非常有用。 非常感谢。

【问题讨论】:

    标签: ios sql objective-c json web-services


    【解决方案1】:
    //Create the request
    
    NSMutableURLRequest *request = [[NSMutableURLRequest alloc] initWithURL:[NSURL URLWithString:@"your script name.php"]];
    // create the Method "GET" or "POST"
    
    [request setHTTPMethod:@"POST"];
    
       //Pass The String to server
    NSString *userUpdate =[NSString stringWithFormat:@"artist_email=%@ ",your string Name,nil];
    
    //Check The Value what we passed
    NSLog(@"the data Details is =%@", userUpdate);
    
    //Convert the String to Data
    NSData *data1 = [userUpdate dataUsingEncoding:NSUTF8StringEncoding];
    
    //Apply the data to the body
    [request setHTTPBody:data1];
    
    //Create the response and Error
    
    NSError *err;
    NSURLResponse *response;
    
    NSData *responseData = [NSURLConnection sendSynchronousRequest:request returningResponse:&response error:&err];
    
    NSString *resSrt = [[NSString alloc]initWithData:responseData encoding:NSASCIIStringEncoding];
    
    //This is for Response 
    NSLog(@"got response==%@", resSrt);
    
    if(resSrt)
    {
        NSLog(@"got response");
    
    
    }
    else
    {
        NSLog(@"faield to connect");
    }
    

    【讨论】:

      【解决方案2】:

      我建议使用 ASP.NET Web API,它支持开箱即用的 JSON 和 XML,并且开发相对容易,因为您不必管理 JSON 数据与 C# 对象之间的解析,然后您可以只需使用实体框架与数据库进行通信。

      开头:http://www.asp.net/web-api/overview/creating-web-apis/creating-a-web-api-that-supports-crud-operations

      还有:http://www.entityframeworktutorial.net/EntityFramework4.3/Introduction.aspx 我认为这有点过时了,但核心将保持不变

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 2016-04-06
        • 1970-01-01
        • 1970-01-01
        • 2015-11-18
        • 1970-01-01
        • 2020-04-06
        • 2016-06-27
        • 1970-01-01
        相关资源
        最近更新 更多