2013-04-05 97 views
-2

我想通過在POST方法的字符串..要創建的字符串POST方法

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

+0

,或者我應該問如何寫一個字符串「」「」; – Akshay 2013-04-05 02:16:34

+0

@Seamus Campbell,dasblinkenlight,CodaFi,Carl Veazey,Monolo我的問題被編輯 – Akshay 2013-04-05 05:24:59

回答

0

從蘋果的文檔上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 
+0

感謝您的幫助Rikkles,其實我的問題是我想傳遞一個json字符串,如{「course_cat_id」:「8」},所以當我使用NSString * body = @「functionName = getCourses_by_category&json = {」course_cat_id「:」8「}」;,我越來越error.and其明顯,你能幫助我。我很困擾這個..... – Akshay 2013-04-05 03:55:06

+0

Rikkles對不起沒有正確地看到答案,我得到了我的答案,感謝這個偉大的幫助,我在你的第一行得到了我的解決方案。謝謝很多 – Akshay 2013-04-05 04:04:53

+0

你能告訴我如何在這段代碼中動態地設置值而不是8 NSString * bodyData = @「functionName = getCourses_by_category&json = {\」course_cat_id \「:\」8 \「}」 – Akshay 2013-04-05 05:12:51