Objective C - POST data using NSURLConnection

后端 未结 4 1047
借酒劲吻你
借酒劲吻你 2021-02-10 18:11

I\'m very slowly working my way through learning the URL loading system for iOS development, and I am hoping someone could briefly explain the following piece of code:



        
4条回答
  •  醉梦人生
    2021-02-10 18:14

    This is a pretty simple HTTP request setup; if you have more specific questions you might do better asking those.

    NSString *myParameters = @"paramOne=valueOne¶mTwo=valueTwo";
    

    This sets up a string containing the POST parameters.

    [myRequest setHTTPMethod:@"POST"];
    

    The request needs to be a POST request.

    [myRequest setHTTPBody:[myParameters dataUsingEncoding:NSUTF8StringEncoding]];
    

    This puts the parameters into the post body (they need to be raw data, so we first encode them as UTF-8).

提交回复
热议问题