-1
我將不得不作出的iOS SDK中的HTTP POST調用,HTTP郵政從IOS SDK
捲曲https://www.googleapis.com/urlshortener/v1/url \ -H '內容類型:應用程序/ JSON' \ -d「{ 「longUrl」: 「http://www.google.com/」}'
對此有何幫助?
我將不得不作出的iOS SDK中的HTTP POST調用,HTTP郵政從IOS SDK
捲曲https://www.googleapis.com/urlshortener/v1/url \ -H '內容類型:應用程序/ JSON' \ -d「{ 「longUrl」: 「http://www.google.com/」}'
對此有何幫助?
很多關於這個問題的答案在這裏和通過谷歌。但是,這是一個代碼示例。如果您需要更多信息,請進行更深入的搜索。
NSMutableURLRequest *theRequest = [NSMutableURLRequest requestWithURL:[NSURL URLWithString:POST_TARGET_URL] cachePolicy:NSURLRequestReloadIgnoringLocalAndRemoteCacheData timeoutInterval:30.0];
[theRequest setHTTPMethod:@"POST"]; // set the method to post
[theRequest addValue:[NSString stringWithFormat:@"multipart/form-data; boundary=%@",QUERY_VALUE_BOUNDRY] forHTTPHeaderField: @"Content-Type"];
NSMutableData *queryData = [[NSMutableData alloc] init];
for (NSString *key in [queryDict allKeys]) { // iterate the keys in an NSDictionary to build the post data with key/value pairs
[queryData appendData:[[NSString stringWithFormat:@"Content-Disposition: form-data; name=\"%@\"\n\n", key] dataUsingEncoding:NSUTF8StringEncoding]];
[queryData appendData:[[NSString stringWithFormat:@"%@", [queryDict objectForKey:key]] dataUsingEncoding:NSUTF8StringEncoding]];
[queryData appendData:[[NSString stringWithFormat:@"\n--%@\n", QUERY_VALUE_BOUNDRY] dataUsingEncoding:NSUTF8StringEncoding]]; // begin bounds
}
[theRequest setHTTPBody:queryData]; // set the data object to the body of the post request
_URLConnection = [[NSURLConnection alloc] initWithRequest:theRequest delegate:self]; // open an NSURLConnection with the request that was just constructed.
這個問題可能至少有2309823094832個回答。你看過他們中的任何一個嗎? – rooftop 2012-08-02 02:49:09