Post data in Objective C using Json

前端 未结 4 1312
[愿得一人]
[愿得一人] 2020-11-27 15:07

I am trying to post data to a PHP web service.
I am familiar doing this in html using query $.post but I am very much stumped trying this in objective C. I tried several

4条回答
  •  有刺的猬
    2020-11-27 15:57

    NSURL *url=[NSURL URLWithString:[NSString stringWithFormat:@"%@posts", SeverURL]];
    ASIHTTPRequest *request = [ASIHTTPRequest requestWithURL:url];
    [request setRequestMethod:@"POST"];
    [request addRequestHeader:@"content-type" value:@"application/json"];
    [request addRequestHeader:@"User-Agent" value:@"iOS"];
    
    request.allowCompressedResponse = NO;
    request.useCookiePersistence = NO;
    request.shouldCompressRequestBody = NO;
    request.delegate=self;
    NSString *json=[[self prepareData] JSONRepresentation];//SBJSON lib, convert a dict to json string
    [request appendPostData:[NSMutableData dataWithData:[json dataUsingEncoding:NSUTF8StringEncoding]]];
    
    [request startSynchronous];
    

提交回复
热议问题