如何在NSURL获取请求中传递查询项?

时间:2016-12-08 18:23:08

标签: ios objective-c

下面是我需要创建的字符串作为GET请求的URL。我总是在NSURL中获得零。 任何人都可以帮助我吗?

  http://example.com/webexternal1/api/Values/sendorder?orderlist={code:"122|155",rate:"60|5",qty:"5|5"}&tab=N2

//strParams = {code:122|155,rate:60|5,qty:5|5}&tab=N2

    dataUrl = [@"http://example.com/webexternal1/api/Values/sendorder?orderlist=" stringByAppendingString:strParams];
            urlComponants = [[NSURLComponents alloc]initWithString:dataUrl];
            NSURL *url = urlComponants.URL;

1 个答案:

答案 0 :(得分:1)

尝试对strParams进行url编码。

NSString* strParams = [@"{code:122|155,rate:60|5,qty:5|5}&tab=N2" stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding];