【问题标题】:How to upload NSData Object to server with specific name?如何将 NSData 对象上传到具有特定名称的服务器?
【发布时间】:2012-02-28 07:09:32
【问题描述】:

如何将 NSData 对象上传到具有特定名称的服务器?

NSData *imgData; // Image Data
NSString *imgName = @"myfile.png";

我想将数据上传到具有特定文件名的服务器。

1. Upload Data (imgData) 

2. To server (my_server.com/upload.html) 

3. With file name (imgName)

【问题讨论】:

标签: iphone html objective-c post nsurlrequest


【解决方案1】:

我目前正在做一个学校项目,我需要做一些类似的事情......

我正在将经度和纬度值放入数据库中。

请注意,可能有更简单的方法可以做到这一点。我绝不是 OBJECTIVE-C 编程的“专业人士”

你需要三样东西。

  1. 您有权访问的服务器。
  2. 将数据写入数据库的 PHP 文件。
  3. 一个 NSURLConnection 对象;

我已将以下代码放在 CLLocationManager 的委托方法之一中。

NSURLConnection 对象应该如下所示:

//this is where I put the url for my PHP file
url = [[NSURL alloc] initWithString:[NSString stringWithFormat:@"http://www.example.com/folder/example.php"]];

urlRequest = [NSURLRequest requestWithURL:url];

connection = [[NSURLConnection alloc] initWithRequest:urlRequest delegate:self];

当然变量:url、urlRequest、connection都是这样在头文件中声明的

NSURL *url;
NSURLRequest *urlRequest;
NSMutableData *filedata;
NSURLConnection *connection;   

【讨论】:

    猜你喜欢
    • 2020-01-19
    • 1970-01-01
    • 2015-12-15
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-06-26
    相关资源
    最近更新 更多