-2

我想在 POST 方法中传递一个字符串..

字符串是@"functionName=getCourses_by_category&json={"course_cat_id":"8"}"

4

1 回答 1

0

来自 Apple 关于如何发送 POST 数据的文档:

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
于 2013-04-05T03:36:11.047 回答