不能发送邮件数据与xcode 6 beta 5
问题描述:
我用Swift发送用户,密码到服务器,但服务器不能收到电子邮件,通过。不能发送邮件数据与xcode 6 beta 5
请让我知道,我错了。
OS X 9.5,iOS的SDK 8.0时,Xcode 6的β5
夫特:
//post data
var post:NSString = "email=\(email_merchant)&password=\(pass_merchant)&appToken=\(token_key)"
//url login
var url:NSURL=NSURL.URLWithString("http://xxx.xxx.xxx/api/sessions")
//add data
var postData:NSData=post.dataUsingEncoding(NSASCIIStringEncoding)!
var postLength:NSString = (String)(postData.length)
var request:NSMutableURLRequest=NSMutableURLRequest(URL: url)
request.HTTPMethod = "POST"
request.HTTPBody=postData
request.setValue(postLength, forHTTPHeaderField: "Content-Length")
request.setValue("application/x-www-form-urlencode", forHTTPHeaderField: "Content-Type")
request.setValue("application/json", forHTTPHeaderField: "Accept")
request.setValue("d54e952e0d0586fc48f1535883ef7008", forHTTPHeaderField: "appToken")
//request.H
var reponseError: NSError?
var reponse: NSURLResponse?
var urlData: NSData? = NSURLConnection.sendSynchronousRequest(request, returningResponse: &reponse, error: &reponseError)
服务器代码:
if(empty($_POST['password'])){
echo json_encode(array ("status"=> "empty pass")) ;
Yii::app()->end();
}
的println(效应初探)
ö
ptional(<NSHTTPURLResponse: 0x7fea9acb1180> { URL: http://xxx.xxx.xxx/api/sessions } { status code: 200, headers {
Connection = "Keep-Alive";
"Content-Encoding" = gzip;
"Content-Length" = 43;
"Content-Type" = "text/html";
Date = "Mon, 29 Sep 2014 11:27:29 GMT";
"Keep-Alive" = "timeout=5, max=100";
Server = "Apache/2.4.7 (Ubuntu)";
Vary = "Accept-Encoding";
"X-Powered-By" = "PHP/5.5.9-1ubuntu4.3";
} })
{
status = "emmty pass";
}
谢谢。
答
当您通过webservices进行访问时,您无法使用普通的post变量访问数据。你需要像这样的phpinput给予$data = file_get_contents("php://input");
答
这是application/x-www-form-urlencoded
而不是application/x-www-form-urlencode
。
你的服务器代码不清楚。你能在这里发布你的服务器代码吗?你如何检索php中的发布数据? – Athipatla 2014-09-29 13:54:57
是的,我正在检索PHP中的发布数据。我使用Yii框架。也许问题是在快速代码 – 2014-09-29 15:32:58
你可以发布代码?因为当您通过webservices访问时,您无法使用普通的post变量访问数据。你需要像phpinput这样''data = file_get_contents(“php:// input”);' – Athipatla 2014-09-30 09:51:35