Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>If you are looking for a working piece of code that posts data, then try this, I have using this, it works great.</p> <p>It takes the data to be sent in dictionary object. Ecodes the data to be sent as POST and then returns the response (if you want the results in string format you can use [[NSString alloc] initWithData:dresponse encoding: NSASCIIStringEncoding]; when returning data)</p> <pre><code>-(NSData*) postData:(NSDictionary *) postDataDic{ NSData *dresponse = [[NSData alloc] init]; NSURL *nurl = [NSURL URLWithString:url]; NSDictionary *postDict = [[NSDictionary alloc] initWithDictionary:postDataDic]; NSData *postData = [self encodeDictionary:postDict]; // Create the request NSMutableURLRequest *request = [NSMutableURLRequest requestWithURL:nurl]; [request setHTTPMethod:@"POST"]; // define the method type [request setValue:[NSString stringWithFormat:@"%d", postData.length] forHTTPHeaderField:@"Content-Length"]; [request setValue:@"application/x-www-form-urlencoded charset=utf-8" forHTTPHeaderField:@"Content-Type"]; [request setHTTPBody:postData]; // Peform the request NSURLResponse *response; NSError *error = nil; dresponse = [NSURLConnection sendSynchronousRequest:request returningResponse:&amp;response error:&amp;error]; return dresponse; } </code></pre> <p>This method prepares the Dictionary data for POST</p> <pre><code> - (NSData*)encodeDictionary:(NSDictionary*)dictionary { NSMutableArray *parts = [[NSMutableArray alloc] init]; for (NSString *key in dictionary) { NSString *encodedValue = [[dictionary objectForKey:key] stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding]; NSString *encodedKey = [key stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding]; NSString *part = [NSString stringWithFormat: @"%@=%@", encodedKey, encodedValue]; [parts addObject:part]; } NSString *encodedDictionary = [parts componentsJoinedByString:@"&amp;"]; return [encodedDictionary dataUsingEncoding:NSUTF8StringEncoding]; } </code></pre> <p>If you have any confusion do let me know.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload