前回の質問がわかりくくなってしまったので改めて質問したいと思います
前回回答してくださった方,ありがとうございます.
Objective-cからPHPへ文字列を渡し、渡された文字列をPHP内で宣言された変数に
に代入したいです。
以下のものを参考にNSSessionクラスを用いてPOAT通信を行いました
通信を行った後,PHPで受け取った文字列をシュミレーターのWebviewで表示しようと思ったのですが受け取りがうまくできません
http://chicketen.blog.jp/archives/1256068.html
https://teratail.com/questions/1891
Objective-cのプログラム
NSURL* url = [NSURL URLWithString:@"http://localhost/posttest1.php"];//POST先url
NSURLSessionConfiguration *config = [NSURLSessionConfiguration defaultSessionConfiguration]; NSMutableURLRequest *request = [NSMutableURLRequest requestWithURL:url]; NSURLSession *session = [NSURLSession sessionWithConfiguration:config]; NSString *text = @"param=aaa"; // postするテキスト NSData *data = [text dataUsingEncoding:NSUTF8StringEncoding]; [request setHTTPBody: [text dataUsingEncoding: NSUTF8StringEncoding]]; [request setValue: @"application/x-www-form-urlencoded" forHTTPHeaderField: @"Content-Type"]; request.HTTPMethod = @"POST"; request.HTTPBody = data; NSURLSessionDataTask *task = [session dataTaskWithRequest:request completionHandler:^(NSData *data, NSURLResponse *response, NSError *error) { // 完了時の処理 }]; [task resume];
//webviewで表示するためのプログラム
NSURLRequest *myRequest = [NSURLRequest requestWithURL:url];
[self.webtest loadRequest:myRequest];
PHPのプログラム
<?php
echo $_POST['param']
?>
送信した文字列をうまく表示できる方法はありますでしょうか?
宜しくお願いします
あなたの回答
tips
プレビュー