Objective c post request not sending the data
NickName:Ios Dev Ask DateTime:2016-01-31T18:52:14

Objective c post request not sending the data

Good day.Im trying to send simple post data to server.This is the code how i do it.

 -(void)makeRequest:(NSString*)stringParameters{
    NSError *error;

    NSURLSessionConfiguration *configuration = [NSURLSessionConfiguration defaultSessionConfiguration];
    NSURLSession *session = [NSURLSession sessionWithConfiguration:configuration delegate:self delegateQueue:nil];
    NSURL *url = [NSURL URLWithString:@"http://vaenterprises.webatu.com/Authentication.php"];
    NSMutableURLRequest *request = [NSMutableURLRequest requestWithURL:url
                                                           cachePolicy:NSURLRequestUseProtocolCachePolicy
                                                       timeoutInterval:60.0];

    [request addValue:@"application/text" forHTTPHeaderField:@"Content-Type"];
    [request addValue:@"application/text" forHTTPHeaderField:@"Accept"];
    [request setHTTPMethod:@"POST"];
     NSString* postData = @"tag=hello&username=yo&something=something";
    [request setHTTPBody:postData];



    NSURLSessionDataTask *postDataTask = [session dataTaskWithRequest:request completionHandler:^(NSData *data, NSURLResponse *response, NSError *error) {

        [self parseJson:data];
    }];

    [postDataTask resume];


}

It looks great till i echo the whole post from php side like this

echo json_encode($_POST);

and i print the result in the iOS like this

-(void)parseJson:(NSData*) data{
    NSString *myString = [[NSString alloc] initWithData:data encoding:NSUTF8StringEncoding];
    NSError *jsonError = nil;
    NSDictionary* jsonObject= [NSJSONSerialization JSONObjectWithData:data options:0 error:&jsonError];
    NSLog(@"%@",myString);
}

this issue is that i get empty string..so it means that post data not being send and that is 10000 percent objective c side issue and i have no clue why its so as in this method we only got setHttpBody with the actual string which contains key and value separated by & but that data not being send as you can see.So what am i doing wrong?Please tell somebody

Copyright Notice:Content Author:「Ios Dev」,Reproduced under the CC 4.0 BY-SA copyright license with a link to the original source and this disclaimer.
Link to original article:https://stackoverflow.com/questions/35112982/objective-c-post-request-not-sending-the-data

More about “Objective c post request not sending the data” related questions

Objective c post request not sending the data

Good day.Im trying to send simple post data to server.This is the code how i do it. -(void)makeRequest:(NSString*)stringParameters{ NSError *error; NSURLSessionConfiguration *configurati...

Show Detail

axios post request not sending data after submit

I'm having troube with my post request, for some reason it doesn't seem to be sending the data its supposed to. When I submit the request I get a status 201 which is great but when I check the http...

Show Detail

cURL request in Objective-C (POST)

I'm struggling translating these cURL requests into Objective - C (I'll change the API keys later): Get request: curl -v -H "app_id:4bf7860a" -H "app_key:0026e51c7e5074bfe0a0c2d4985804b2" -X GET...

Show Detail

Passing data to objective c with POST rather than GET

I have been using the url intercept method to pass data from javascript to objective C by passing the data as url encoded parameters and using NSURLProtocol to intercept the request however I am now

Show Detail

Objective-C POST request not sending data

I have a method that should post some data to a PHP file: -(void)submitForm { NSLog(@"name=%@", formName.text); // returns correct value NSString *post = [NSString stringWithFormat:@"name...

Show Detail

As sending Bytes image by post in Objective-C

As sending Bytes image by post in Objective-C. http://192.168.1.50:8080 { "username":"mariob", "password":"123", "name":"Miguel", "surname":"perez",&#x

Show Detail

Sending Post Request from iOS Simulator to Local Host

I've been trying to figure this out all morning. I'm sending a POST request from an Objective-C method to a local server on my Mac, using MAMP. When the code runs, the Objective-C method appears to

Show Detail

Using POST to send data back to objective c

I am attempting to send data back to my objective c program from javascript. I found a very helpful question here that got me started, but I quickly ran into a problem: the post seems to be faili...

Show Detail

POST request in Objective-C

Searching the web for some method to send POST requests in Objective-C, I came up with some solutions. That's what I've got: responseData = [NSMutableData new]; NSURL *url = [NSURL URLWithString:...

Show Detail

Sending an HTTPS request using C on Mac OS X

Questions like this and this show you how to send an HTTP POST request using Cocoa and objective-c. Is there any way to use that code in C? Furthermore, how to send an HTTPS (SSL) POST request usi...

Show Detail