2012-10-01 23 views
0

我提供了GET请求。在API字符串内部,我应该放入一些数据,我在运行应用程序后会得到 ,所以我需要将整个字符串分成两部分,并将结果放在resultText之间。所以我用startQuery和endQuery做了。但我有一个失败,而建立这个应用程序。希望有人有一个想法。下面是一些截图: Failure XCode description将请求链接划分为两部分

- (void)makeRequest 
{ 
    if (_responseData == nil) 
    { 
     _responseData = [NSMutableData new]; 
    } 

    NSString* startQuery = [NSString stringWithString:@"https://www.wikifood.eu/wikifood/en/struts/xxxxxxxx.do?method=getProductOverview&query="]; 
    NSString* endQuery = [NSString stringWithString:@"&startAt=0&limit=5&filter=true&loginname=xxxxxx&password=6f052cxxx15a4c2813baf3x75xx51dead1f4fe2"]; 

    NSURL *url = [NSURL URLWithString:[[NSString stringWithFormat:@"%@%@%@", startQuery, resultText.text, endQuery] stringByAddingPercentEscapesUsingEncoding:NSASCIIStringEncoding]]; 

    NSURLRequest* request = [NSURLRequest requestWithURL:url]; 
    _urlConnection = [[NSURLConnection alloc] initWithRequest:request delegate:self]; 
} 

感谢。

回答

1

您看到的两个警告是因为当您只使用文字字符串时,您正在使用NSString stringWithString

替换:

NSString* startQuery = [NSString stringWithString:@"https://www.wikifood.eu/wikifood/en/struts/xxxxxxxx.do?method=getProductOverview&query="]; 
NSString* endQuery = [NSString stringWithString:@"&startAt=0&limit=5&filter=true&loginname=xxxxxx&password=6f052cxxx15a4c2813baf3x75xx51dead1f4fe2"]; 

有了:

NSString* startQuery = @"https://www.wikifood.eu/wikifood/en/struts/xxxxxxxx.do?method=getProductOverview&query="; 
NSString* endQuery = @"&startAt=0&limit=5&filter=true&loginname=xxxxxx&password=6f052cxxx15a4c2813baf3x75xx51dead1f4fe2"; 
+0

非常感谢,这是原因。现在它可以工作。 –

0

不知道,但你添加%的逃生: stringByAddingPercentEscapesUsingEncoding:NSASCIIStringEncoding

但你这样做对整个串......我想你的意思是:

NSURL *url = [NSURL URLWithString:[NSString stringWithFormat:@"%@%@%@", startQuery, [resultText.text stringByAddingPercentEscapesUsingEncoding:NSASCIIStringEncoding], endQuery]]; 

你”重新URL并不需要进行转义,你知道,这是确定的,只是你的“不安全”的文本

还是那句话:不知道,我还没有打开的XCode尝试^^

+0

谢谢,我会尝试一下。 –