我想在POST方法中传递一个字符串..
字符串为@"functionName=getCourses_by_category&json={"course_cat_id":"8"}"
答案 0 :(得分:0)
来自Apple的how to send POST data文档:
NSString *bodyData = @"functionName=getCourses_by_category&json={\"course_cat_id\":\"8\"}";
NSMutableURLRequest *postRequest = [NSMutableURLRequest requestWithURL:[NSURL URLWithString:@"https://www.apple.com"]];
// Set the request's content type to application/x-www-form-urlencoded
[postRequest setValue:@"application/x-www-form-urlencoded" forHTTPHeaderField:@"Content-Type"];
// Designate the request a POST request and specify its body data
[postRequest setHTTPMethod:@"POST"];
[postRequest setHTTPBody:[NSData dataWithBytes:[bodyData UTF8String] length:[bodyData length]]];
// Initialize the NSURLConnection and proceed as usual