【问题标题】:Pass NSString to PHP script [duplicate]将 NSString 传递给 PHP 脚本 [重复]
【发布时间】:2014-06-17 19:43:27
【问题描述】:

我目前有以下代码

-(void)returnToSQL
{
    NSURL *url = [NSURL URLWithString:@"http://babyfood.30ptdesign.com\....php"];

    NSData *dataUrl = [NSData dataWithContentsOfURL:url];

    NSString *strResult = [[NSString alloc] initWithData:dataUrl encoding:NSUTF8StringEncoding];
    NSLog(@"%@",strResult);
}

我需要将一个名为_usernameNSString 传递到PHP 文件中的同名变量中,而不使用ASIFormDataRequest

有没有办法做到这一点?我还没找到。

【问题讨论】:

  • 查看 NSURLRequest 和 NSURLConnection 并确保阅读 GET 和 POST 请求。

标签: php ios objective-c post


【解决方案1】:

用参数调用你的 php。

类似的东西

http://domain/file.php?param=string

在你的 php 中

<?php
  $param = $_GET['param'];
  echo $param;
?>

【讨论】:

  • 这对第一个变量非常有效,谢谢!如何添加第二个变量? IE。 domain/file.php?param1=string1?param2=string2 不起作用。我该怎么写呢?
  • 有可能这样做。但是我自己没有尝试过,但它应该是这样的: http://domain/test.php?param1=param1&param2=param2&param3=param3 永远记住在使用数据库时要避免 sql 注入!那里有几个教程! :)
猜你喜欢
  • 2015-06-02
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2012-08-19
  • 2013-06-18
  • 2011-08-31
  • 2016-08-03
  • 2012-11-15
相关资源
最近更新 更多