Passing data to objective c with POST rather than GET

前端 未结 3 1651
情书的邮戳
情书的邮戳 2020-12-29 16:54

I have been using the url intercept method to pass data from javascript to objective C by passing the data as url encoded parameters and using NSURLProtocol to intercept the

3条回答
  •  陌清茗
    陌清茗 (楼主)
    2020-12-29 17:47

    You should definitely use a POST. You just need to set up the request for it. You may need to make sure that the data is encoded and take care of a couple other details.:

    NSMutableURLRequest *request = [NSMutableURLRequest requestWithURL:url];
    [request setHTTPMethod:@"POST"];
    [request setValue:myMimeType forHTTPHeaderField:@"Content-Type"];
    [request setValue:[NSString stringWithFormat:@"%d", requestData.length]       
             forHTTPHeaderField:@"Content-Length"];
    
    [request setHTTPBody:requestData];
    
    [self.playerView loadRequest: request];
    

    Alternatively, you can send a multi-part document or form values.

提交回复
热议问题