0

我有一个带有参数的 URL。在火狐中。我有下载插件并找到请求的参数。我在 httpFox 插件工具上找到了 PostData 选项卡,我看到了参数和值。

我创建了一个字符串并添加了参数,并对该字符串值进行了编码

NSString *parameterId = [NSString StringWithFormat:@"ac$2_sdrex_es34_4333f=Caa111"];

NSString EncodeID = [parameterId
  stringByAddingPercentEscapesUsingEncoding:NSASCIIStringEncoding];

...并创建了 PostData,

PostData = [encodeID  dataUsingEncoding:NSASCIIStringEncoding allowLossyConversion:YES];

...并设置 postLength,

NSString *postLength = [NSString stringWithFormat:@"%d", [postData length]];

...并设置 http 标头值,

[request setValue:postLength forHttpHeaderField:@"Content-Length"];
[request setHTTPBody:postData];

然后建立连接,

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

但这会导致以下错误...

Error Domain = NSURLErrorDomain code= -1002 unsupported url

我也对 URL 进行了编码。

谁能告诉我如何解决这个问题?

这就是创建 postData 后的内容!

NSURL *url = [NSURL URLWithString:urlString];    
    theRequest = [[NSMutableURLRequest alloc]initWithURL:url];

    [theRequest setValue:@"win-eqjf1b1ep06:20000" forHTTPHeaderField:@"Host"];
    [theRequest setValue:@"Mozilla/5.0 (Macintosh; U; Intel Mac OS X 10.6; en-US; rv:1.9.2.10) Gecko/20100914 Firefox/3.6.10" forHTTPHeaderField:@"User-Agent"];
    [theRequest setValue:@"text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8" forHTTPHeaderField:@"Accept"];
    [theRequest setValue:@"en-us,en;q=0.5" forHTTPHeaderField:@"Accept-Language"];
    [theRequest setValue:@"gzip,deflate" forHTTPHeaderField:@"Accept-Encoding"];
    [theRequest setValue:@"ISO-8859-1,utf-8;q=0.7,*;q=0.7" forHTTPHeaderField:@"Accept-Charset"];
    [theRequest setValue:@"115" forHTTPHeaderField:@"Keep-Alive"];
    [theRequest setValue:@"keep-alive" forHTTPHeaderField:@"Connection"];


    [theRequest setValue:postLength forHTTPHeaderField:@"Content-Length"];
    [theRequest setHTTPBody:postData];

@all 在此先感谢

4

1 回答 1

0

NSMutableURLRequest 仅支持 http://、https://、ftp:// 或 file://

http://developer.apple.com/library/ios/#DOCUMENTATION/Cocoa/Conceptual/URLLoadingSystem/URLLoadingSystem.html#//apple_ref/doc/uid/10000165i

你在使用其他协议吗?

于 2012-08-06T10:29:52.467 回答