1

I'm trying to execute a PHP script which increments a field in a database. I have the script working and I am currently modifying the database perfectly using ASIHTTPRequest, but I feel as though I should be using a different method given that I do not need a return.

Is this what's called an HTTP POST?

    incrementOrDecrementURL = [[NSString alloc] initWithFormat:@"http://myURL/doScript.php"];

NSURL *requestURL = [[NSURL alloc] initWithString:incrementOrDecrementURL];

//The actual request
ASIHTTPRequest *request = [ASIHTTPRequest requestWithURL:requestURL];
// Becoming the request delegate
//To get callbacks like requestFinished: or requestFailed:
[request setDelegate:self];    

// Start request
[request startAsynchronous]; 

3 Answers 3

1

form the docs: Sending a form POST with ASIFormDataRequest

ASIFormDataRequest *request = [ASIFormDataRequest requestWithURL:url];
[request setPostValue:@"Ben" forKey:@"first_name"];
[request setPostValue:@"Copsey" forKey:@"last_name"];
[request setFile:@"/Users/ben/Desktop/ben.jpg" forKey:@"photo"];

But also note, that ASIHTTPRequest is not maintained anymore by it's original author.

Sign up to request clarification or add additional context in comments.

2 Comments

so, should I transfer to a different API? If so, which would you recommend? Thanks.
the post I linked has some recommendations. I am using AFNetworking now.
0

It would be a oneway request, not a POST.

But, you should never update any database with a GET request, so you should use a POST.

One way to do this is to immediately return a response, and then update the database, but the better approach, since this library is no longer maintained (http://allseeing-i.com/ASIHTTPRequest/) you may want to use NSUrlConnection and just ignore the response, and go on.

2 Comments

@James.Black Coming back to your approcah with the NSURLConnection...do you think this is feasible? I basically want the user to be able to press a button and have this script executed in the background.....
@derek.lo - Yes, you can do this in the background. Look at this: stackoverflow.com/questions/1728631/…
0

ASIHTTPRequest by default sends a GET request, not POST. It's proper that GETs don't update anything at the server, so you should use a POST: [request setRequestMethod:@"POST"]. You can just have your doScript.php return an HTTP 204 No Content response. PHP header() function. But it's good design to return at least some sort of protocol-specific status code regarding what actually happened at the server. I often just return a simple JSON response such as {"status":"OK"}.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.