Objective C - POST data using NSURLConnection

后端 未结 4 1021
独厮守ぢ
独厮守ぢ 2021-02-10 17:33

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:38

    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).

提交回复
热议问题