gpt4 book ai didi

xcode - 无法使用 xcode 6 beta 5 发送发布数据

转载 作者:行者123 更新时间:2023-11-28 05:33:48 25 4
gpt4 key购买 nike

我使用 Swift 将用户名、密码发送到服务器,但服务器无法接收电子邮件、密码。

请让我知道我错在哪里。

OS X 9.5、iOS SDK 8.0、Xcode 6 beta 5

swift :

       //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";
}

谢谢。

最佳答案

当您通过 web 服务访问时,您无法使用普通的 post 变量访问数据。你需要像这样给 phpinput $data = file_get_contents("php://input");

关于xcode - 无法使用 xcode 6 beta 5 发送发布数据,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26099166/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com