简体   繁体   English

我如何通过json将数据从设备发送到我的php文件

[英]how can i send data from my device to my php file via json

i couldn't send data from my device to my php file. 我无法将数据从设备发送到我的php文件。 i am trying to send data from device using json. 我正在尝试使用json从设备发送数据。 this is my php code 这是我的PHP代码

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

and my client code: 和我的客户代码:

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];

}

-(void)connectionDidFinishLoading:(NSURLConnection *)connection { -(void)connectionDidFinishLoading:(NSURLConnection *)connection {

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);

i couldnt find the problem. 我找不到问题。 can you help me? 你能帮助我吗?

I'd recommend you following two libraries, they will make it very easy to do your task: 我建议您使用以下两个库,它们将使您轻松完成任务:

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何从安装程序将数据发送到php文件? - How do I send data to a php file from my installer? 我可以从浏览器控制台(通过AJAX)将信息发送到本地/远程主机上的php文件吗? - Can I send information from browser console (via AJAX) to my php file on local/remote host? 使用php从大型JSON文件中提取数据:如何在代码中实现侦听器接口 - Extracting data from large JSON file using php: How can I implement listener interface in my code 如何通过php发送短信,该短信来自我的电话号码而不是第三方应用程序/号码? - How can I send an SMS via php, originating from my phone number and not a third party app/number? 如何通过ajax从summernote编辑器中将数据发送到php文件? - How can I send data from a summernote editor via ajax to a php file? 如何使用ajax将json数据发送到php文件 - How can I send json data to php file with ajax 如何将远程 web 主机上的 php 文件中的数据发送到我计算机上的 c# 应用程序? - how do i send data from a php file on a remote web host to a c# application on my computer? 如何通过PHP从客户端向服务器获取javascript整理的数据 - How can I get my javascript gererated data from the client to the server via PHP 如何在php中通过json发送数据 - How can I send data by json in php 如何编写此 JS 代码以从我的 php 文件中检索 JSON 数据? - How do I write this JS code to retrieve JSON data from my php file?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM