NSURL URLWithString 到相对 URL

问题描述 投票:0回答:1

我想从 iOS 应用程序上传图像 (

UIImage
) 到 Django 网站。(其中有表单和提交按钮,就像普通网页一样。)

所以我决定使用

ASIFormDataRequest
来实现这一点。 (我是新人,我做得对吗?)

首先,

NSURL *url = [NSURL URLWithString:@"http://someec2site/profile/album/2/upload/"];

错误:当前 URL

profile/album/2/upload/
与其中任何一个都不匹配。

所以,我做到了,

NSURL *url = [NSURL URLWithString:@"http://someec2site/profile/albums/(?P<album_id>\d+)/upload/"];

错误:未知的转义序列 '\d'

我有一个问题。

  1. 我做得对吗?

  2. 如何获取字符串的相对 URL? (根据url.py重定向URL)

ios django upload
1个回答
0
投票

首先,您选择使用 ASI 对于 HTTP 请求非常有好处。

如果我没记错的话,您正在尝试为不同的专辑 ID 构建上传 URL。

你为什么不试试这个:

NSString * urlString = [NSString stringWithFormat:@"http://someec2site/profile/album/%d/upload/",albumId];
NSURL * url = [NSURL urlWithString:urlString];
© www.soinside.com 2019 - 2024. All rights reserved.