gpt4 book ai didi

php无法从Swift编写的Xcode程序获取参数

转载 作者:行者123 更新时间:2023-11-30 14:18:01 25 4
gpt4 key购买 nike

我无法获取从swift代码发送的参数。如果我忽略该参数,我可以获得返回结果。请帮忙。谢谢

Swift 代码:

    var url: NSURL = NSURL(string: urlPath)!
var request = NSMutableURLRequest(URL: url)
request.HTTPMethod = "POST"
request.timeoutInterval = 60
request.setValue("application/json; charset=utf-8", forHTTPHeaderField: "Content-Type")
var searchString = ""
var bodyData: NSString = "brandCode=BU&model=test1234"
request.HTTPBody = bodyData.dataUsingEncoding(NSUTF8StringEncoding)
var connection:NSURLConnection = NSURLConnection(request: request, delegate: self, startImmediately: false)!

connection.start()
<小时/>

PHP 代码:

    $brandCode=$_POST['brandCode'];
$model=$_POST['model'];
$cnx=odbc_connect('testODBC','testing','testing');
$sql="select * from brand where brand='".$brandCode."' and model='".$model."'";
$cur= odbc_exec($cnx, $sql);
while($info = odbc_fetch_array($cur))
{
$resultArray[]=array($info);
}
echo json_encode($resultArray);

最佳答案

尝试使用此代码

var URL: NSURL = NSURL(string: "http://example.com")
var request:NSMutableURLRequest = NSMutableURLRequest(URL:URL)
request.HTTPMethod = "POST"
var bodyData = "brandCode=BU&model=test1234"
request.HTTPBody = bodyData.dataUsingEncoding(NSUTF8StringEncoding);
NSURLConnection.sendAsynchronousRequest(request, queue: NSOperationQueue.mainQueue())
{
(response, data, error) in
println(NSString(data: data, encoding: NSUTF8StringEncoding))
}

关于php无法从Swift编写的Xcode程序获取参数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30889310/

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