Jump to content

How send text on HTTP POST wordpress?


2 posts in this topic

Recommended Posts

In my app I am using this code for sending parameters name, email, website url and comment in blog...Probably some value are wrong setting...Someone can help me solved? I'm going crazy!! Thanks in advance!

 

 

-(void)invia{

    

   

        

    NSURL *indirizzo = [NSURL URLWithString:@"http://z****.altervista.org/********/feed/"];

    

    

    NSMutableURLRequest *request = [NSMutableURLRequest requestWithURL:[indirizzo standardizedURL]];

        

        

    

    [request setCachePolicy:NSURLRequestReloadIgnoringLocalCacheData];

    [request setHTTPShouldHandleCookies:NO];

    [request setHTTPMethod:@"POST"];

    

    //[request setValue:@"application/json" forHTTPHeaderField:@"Accept"];

   

    

        NSDictionary *parametri = [NSDictionary dictionaryWithObjectsAndKeys:

                                   campoSito.text, @"url",

                                   campoNome.text, @"author",

                                   campoEmail.text, @"email",

                                   campoCommento.text, @"content", nil];

        

        NSMutableArray *values = [NSMutableArray new];

        

        [parametri enumerateKeysAndObjectsUsingBlock:^(id key, id obj, BOOL *stop) {

            // Create an encoded parameter pair -> k=v

            NSString *p = [NSString stringWithFormat:@"%@=%@", key, [[obj description] stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding]];

            [values addObject:P];

        }];

        

        

        

        NSString *dati_postati = [values componentsJoinedByString:@"&"];

    

    [request setValue:@"application/x-www-form-urlencoded; charset=utf-8" forHTTPHeaderField:@"Content-Type"];

    

    

    [request setHTTPBody:[dati_postati dataUsingEncoding:NSUTF8StringEncoding]];

    

    

   

    connetti = [[NSURLConnection alloc] initWithRequest:request delegate:self];

    

       

    

    [connetti start];

        

        

    [self dismissViewControllerAnimated:YES completion:nil];

    

    campoCommento.text=nil;

    campoEmail.text=nil;

    campoSito.text=nil;

    campoNome.text=nil;

      

    

    

}

 
Link to comment
Share on other sites

  • 3 weeks later...
 Share

×
×
  • Create New...