【问题标题】:How to consume post type restful wcf service in iphone?如何在 iphone 中使用 post 类型的 restful wcf 服务?
【发布时间】:2011-08-30 02:30:34
【问题描述】:

我正在使用“GET”类型的 JSON 格式的宁静 WCF 服务。 我想知道如何使用“POST”类型的服务,以便我可以发送大量数据。

这是我的“GET”类型代码:

NSURL *jsonURL = [NSURL URLWithString:[NSString stringWithFormat:@"http://www.xxx.com   /coffeeiphone/Service.svc/maintransactioninsert/%@/%@/%@",stockid,[format stringFromDate:selected],[quantity text], nil]];

NSString *jsonData = [[NSString alloc] initWithContentsOfURL:jsonURL];   

【问题讨论】:

标签: iphone objective-c wcf rest post


【解决方案1】:

对于 GET,它可以像上面那样只获取 URL 的内容。 对于 POST,您必须创建一个 NSMutableURLRequest。

NSURL *theUrl = [NSURL URLWithString:@"yourURL"];
NSMutableURLRequest *theRequest = [[NSMutableURLRequest alloc] initWithURL:theUrl];
[theRequest setHTTPMethod:@"POST"];
//set the body of your request:
[theRequest setHTTPBody: //request here];
//get your response:
NSData *response = [NSURLConnection sendSynchronousRequest:theRequest returningResponse:nil error:nil];

要构造 JSON,请尝试查看 json-framework。 https://github.com/stig/json-framework/

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-09-30
    • 1970-01-01
    • 2011-05-30
    • 1970-01-01
    • 2013-05-04
    • 2011-01-02
    相关资源
    最近更新 更多