-1

iOSSDKでHTTPPOST呼び出しを行う必要があります。

curl https://www.googleapis.com/urlshortener/v1/url \ -H'Content-Type:application / json' \ -d'{"longUrl": "http://www.google.com/"} '

これについて何か助けはありますか?

4

1 に答える 1

0

これに対する多くの回答が、こことグーグル経由で入手できます。ただし、ここにコードサンプルがあります。さらに詳しい情報が必要な場合は、より深い検索を行ってください。

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.
于 2012-08-02T03:10:42.153 に答える