के साथ PHP स्क्रिप्ट में कुंजी-मान जोड़े को पास करने के लिए NSURLRequest का उपयोग करना मैं उद्देश्य-सी के लिए बिल्कुल नया हूं, और POST का उपयोग करके एक PHP स्क्रिप्ट में कई कुंजी-मूल्य जोड़े को पास करने के लिए देख रहा हूं। मैं निम्नलिखित कोड का उपयोग कर रहा हूं लेकिन डेटा को पोस्ट करने के लिए प्रतीत नहीं होता है। मैंने NSData का उपयोग करके सामान भेजने की कोशिश की, लेकिन न ही काम करने लगते हैं।POST
NSDictionary* data = [NSDictionary dictionaryWithObjectsAndKeys:
@"bob", @"sender",
@"aaron", @"rcpt",
@"hi there", @"message",
nil];
NSURL *url = [NSURL URLWithString:@"http://myserver.com/script.php"];
NSMutableURLRequest *request = [NSMutableURLRequest requestWithURL:url];
[request setHTTPMethod:@"POST"];
[request setHTTPBody:[NSData dataWithBytes:data length:[data count]]];
NSURLResponse *response;
NSError *err;
NSData *responseData = [NSURLConnection sendSynchronousRequest:request returningResponse:&response error:&err];
NSLog(@"responseData: %@", content);
यह इस सरल स्क्रिप्ट के लिए भेजा जा रहा है एक डाटाबेस डालने प्रदर्शन करने के लिए:
<?php $sender = $_POST['sender'];
$rcpt = $_POST['rcpt'];
$message = $_POST['message'];
//script variables
include ("vars.php");
$con = mysql_connect($host, $user, $pass);
if (!$con)
{
die('Could not connect: ' . mysql_error());
}
mysql_select_db("mydb", $con);
mysql_query("INSERT INTO php_test (SENDER, RCPT, MESSAGE)
VALUES ($sender, $rcpt, $message)");
echo "complete"
?>
कोई भी विचार?
pinkgothic के लिए धन्यवाद, मैं हूँ अब बोली-enclosing मेरी डालने बयान, लेकिन यह केवल DB को खाली मान जोड़ रहा है । मुझे लगता है कि इसका मतलब है कि मूल्य अभी भी ठीक से पोस्ट नहीं किए जा रहे हैं? –