2012-02-26 61 views
0

我無法從我的設備發送數據到我的PHP文件。我試圖使用json從設備發送數據。 這是我的PHP代碼我怎麼能從我的設備發送數據到我的PHP文件通過JSON

$cevap = $_POST["cevap"]; 
echo $cevap; 

和我的客戶端代碼:

NSString* postBody = @"cevap=ali"; 
NSLog(@"%@",postBody); 
NSLog(@"postbody: %@",postBody); 


NSData *postData = [postBody dataUsingEncoding:NSUTF8StringEncoding]; 


NSURL* urlData = [NSURL URLWithString:@"http://yatanadam.com/sonuc.php"]; 



NSMutableURLRequest* request1 = [NSMutableURLRequest requestWithURL:urlData 
                 cachePolicy: 
           NSURLRequestUseProtocolCachePolicy timeoutInterval:60.0]; 


[request1 setHTTPMethod:@"POST"]; 
[request1 setHTTPBody:postData]; 
[request1 setValue:[NSString stringWithFormat:@"%d",[postData length]] 
    forHTTPHeaderField:@"Content-Length"]; 

conn = [[NSURLConnection alloc] initWithRequest:request1 delegate:self]; 
if (conn) { 

    receivedData = [[NSMutableData data] retain]; 

} 

- (空)connectionDidFinishLoading:(NSURLConnection的*)連接{

receivedString = [[NSString alloc] initWithData:receivedData encoding:NSUTF8StringEncoding]; 
SBJSON *parser = [[SBJSON alloc] init]; 
result = [parser objectWithString:receivedString error:nil]; 
[parser release], parser = nil; 
// Set tableData 
NSLog(@"%@",result); 

我不能發現問題。你可以幫我嗎?

回答

0

我建議你以下兩個庫,他們將使它很容易做你的任務:

相關問題