English 中文(简体)
NSMutableURL 上的内存管理
原标题:memory management on NSMutableURLRequest
  • 时间:2012-05-22 05:23:36
  •  标签:
  • iphone

I am new to iPhone Development . and my question is on memory management Here is my code :

- (void)asynchronousRequestServerWithXMLPost:(NSString *)urlAddress PostData:(NSString *)postContent {

urlAddress = [self encodeStringForURL:urlAddress];
theRequest = [[[NSMutableURLRequest alloc] init]autorelease];
[theRequest setURL:[NSURL URLWithString:urlAddress]];
if([postContent length] > 0) {
    [theRequest setHTTPMethod:@"POST"];
时 时 else {
    [theRequest setHTTPMethod:@"GET"];
时 时



NSData *theBodyData = [postContent dataUsingEncoding:NSUTF8StringEncoding allowLossyConversion:YES];
[theRequest setValue:@"application/x-www-form-urlencoded charset=utf-8" forHTTPHeaderField:@"Content-Type"];
NSString *postLength = [NSString stringWithFormat:@"%d", [theBodyData length]];
[theRequest setValue:postLength forHTTPHeaderField:@"Content-Length"];
[theRequest setHTTPBody:theBodyData];    

[NSThread detachNewThreadSelector:@selector(sendSyncRequest) toTarget:self withObject:nil];

时 时

我得到的渗漏在这些线上:

theRequest = [[[NSMutableURLRequest alloc] init]autorelease];
[theRequest setURL:[NSURL URLWithString:urlAddress]];
NSData *theBodyData = [postContent dataUsingEncoding:NSUTF8StringEncoding allowLossyConversion:YES];
[theRequest setValue:@"application/x-www-form-urlencoded charset=utf-8" forHTTPHeaderField:@"Content-Type"];

If anyone can help then help me. Thanking You.

最佳回答

我猜你的泄密 是由这条线造成的

urlAddress = [self encodeStringForURL:urlAddress];

我需要看看你的编码代码 stringForURL,但我猜如果你把它传回去时没有自动解密的话。此外,我也不会将这种方法的结果指定给参数变量,然后你就会失去引用。你应该这样做,而不是这样:

NSString *encodedUrlAddress = [self encodeStringForURL:urlAddress];

然后在调用 URLWring String 时使用编码dUrl 地址。

问题回答

暂无回答




相关问题
Code sign Error

I have created a new iPhone application.I have two mach machines. I have created the certificate for running application in iPhone in one mac. Can I use the other mac for running the application in ...

ABPersonViewController Usage for displaying contact

Created a View based Project and added a contact to the AddressBook using ABAddressBookRef,ABRecordRef now i wanted to display the added contact ABPersonViewController is the method but how to use in ...

将音频Clips从Peter改为服务器

我不禁要问,那里是否有任何实例表明从Peit向服务器发送音响。 I m不关心电话或SIP风格的解决办法,只是一个简单的袖珍流程......

• 如何将搜查线重新定位?

我正试图把图像放在搜索条左边。 但是,问题始于这里,搜索条线不能重新布署。

热门标签