使用 ASIFormDataRequest 从 iPhone 发布请求不起作用
这里是 Rails/iOS 新手。我有一个 Rails 博客应用程序。我正在尝试使用带有 ASIFormDataRequest 的 HTTP POST 方法从 iOS 上传帖子。这是调用的代码:
NSURL *url=[[NSURL alloc] initWithString:@"http://localhost:3000/posts"];
ASIFormDataRequest *request = [ASIFormDataRequest requestWithURL:url];
[request setPostValue:@"Ben" forKey:@"name"];
[request setFile:@"star.png" forKey:@"image"];
[request startSynchronous];
NSString *response = [request responseString];
NSLog(@"response:: %@", response);
当我运行此代码时,没有任何反应。无法联系我的服务器。我得到回复::(空)。知道为什么吗?
编辑 我发现 star.png 需要有其完整的文件地址。现在 POST 工作正常,但名称或图像都没有保存到数据库中。将创建一个名称和图像为空的新帖子。知道为什么吗?
Newbie to Rails/iOS here. I have a rails blog application. I'm trying to upload a post from iOS using an HTTP POST method with ASIFormDataRequest. Here's the code that get's called:
NSURL *url=[[NSURL alloc] initWithString:@"http://localhost:3000/posts"];
ASIFormDataRequest *request = [ASIFormDataRequest requestWithURL:url];
[request setPostValue:@"Ben" forKey:@"name"];
[request setFile:@"star.png" forKey:@"image"];
[request startSynchronous];
NSString *response = [request responseString];
NSLog(@"response:: %@", response);
When I run this code, nothing happens. My server does not get contacted. I get response:: (null). Any idea why?
EDIT I found out that star.png needed to have its full file address. Now the POST works fine, but neither the name or image get saved into the db. A new post with empty name and image gets created. Any idea why?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
对于“imagePath”是图像的路径。完整路径。
For the "imagePath" is the path to your image. The full path.
为什么你在这里使用本地主机?
使用您的网络服务器 IP 而不是 localhost
why you are using localhost here?
use your web server ip instead of localhost