How can i post json string to server

前端 未结 4 1796
清歌不尽
清歌不尽 2020-12-16 08:22

This is json string that I have to post...

{
    \"data\": {
        \"description\": \"\",
        \"current_value\": \"\",
        \"serialno\": \"\",
            


        
4条回答
  •  温柔的废话
    2020-12-16 08:53

    • As per my point of view you can Use NSURLSeession with Asyn request (Try to implement NSURLSession)

    NSData *postData =[NSJSONSerialization dataWithJSONObject:Data options:0 error:&error];

    if (!error)
    {
        NSString *urlpart = [NSString stringWithFormat:@“Your URL];
        NSURL *requestUrl = [NSURL URLWithString:urlpart];
        NSMutableURLRequest *URLRequest = [NSMutableURLRequest requestWithURL:requestUrl cachePolicy:NSURLRequestUseProtocolCachePolicy timeoutInterval:60.0];
        URLRequest.allowsCellularAccess=YES;
        [URLRequest setHTTPMethod:@"POST"];
        [URLRequest setValue:@"application/json; charset=utf-8" forHTTPHeaderField:@"Content-Type"];
        [URLRequest setHTTPBody:postData];
        WebServiceManager *webserviceManager = [[WebServiceManager alloc] init];// this is your comman class for webServices connections 
        [webserviceManager sendRequest:URLRequest withOwner:self successAction:@selector(delegateMethod:) failAction:@selector(Error:)];
    }
    

提交回复
热议问题