Note that there are some explanatory texts on larger screens.

plurals
  1. POASIHTTPRequest - Response Correct in Debug Window but Null in Browser
    text
    copied!<p>I've never used ASIHTTPRequest before, nor have I dealt with posting anything from an iPhone to a web service before. I'd like to eventually save the posted variables to a database, but I am unsure if they are being posted properly at this time. When I run the following script in Xcode, I see the correct html code with inserted variables logged in the debug window. My concern is that I don't see the same thing when I access the page in the browser. My guess is this is to be expected, but I'm not completely sure. Here is what I am doing:</p> <pre><code>string1 = [[NSString alloc] initWithString:@"Did this"]; string2 = [[NSString alloc] initWithString:@"come through?"]; NSString *urlString = @"http://www.myurl.com/post_test.php"; NSURL *url = [NSURL URLWithString: urlString]; ASIFormDataRequest *request = [ASIFormDataRequest requestWithURL:url]; [request setPostValue:string1 forKey:@"String1"]; [request setPostValue:string2 forKey:@"String2"]; NSString *response = nil; [request startSynchronous]; NSError *error = [request error]; if (!error) { response = [request responseString]; NSLog(@"Response GOOD: %@", response); } else { NSLog(@"Response BAD: %@", error); } </code></pre> <p>This prints the html code from the web page with the uploaded variables correctly, but if I go to the page in my browser the php variables are null. Here is the small php script:</p> <pre><code>&lt;?php $received = array(); $received = $_POST; $print_received = print_r($received, TRUE); echo "&lt;pre&gt;$print_received&lt;/pre&gt;"; $var1 = $received['String1']; $var2 = $received['String2']; echo "The message received was: $var1 $var2&lt;/br&gt;"; ?&gt; </code></pre> <p>I haven't added the mysql connection code yet because I want to make sure this posting business is successful first.</p>
 

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