Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Incorrect NSStringEncoding value 0x0000 detected

I am using ASIHttpRequest library in iphone and when i try to do a GET request on the below URL i get this message and the request fails, please anyone if he/she has encountered this problem or know a possible solution to it please let me know. Secondly if i paste the link in the browser it works perfectly fine.

[URL]

http://www.rugsale.com/iphone/app/?type=product_list&params=id%3D334&ver=1.0&key=kaoud

[ERROR]

Incorrect NSStringEncoding value 0x0000 detected. Assuming NSStringEncodingASCII. Will stop this compatiblity mapping behavior in the near future.

Thx in advance

Regards

Syed Arsalan Pervez www.saplogix.net

like image 848
Syed Arsalan Pervez Avatar asked Nov 30 '10 19:11

Syed Arsalan Pervez


2 Answers

This notably happens if you call [asiHttpRequest getResponseString] before a valid response has been returned and the request encoding has been set (i.e. couldn't connect to server).

The easiest way to workaround this warning is by editing the ASIHTTPRequest class, remove the @synthesize responseEncoding and adding a simple custom getter/setter so you can return the default encoding if the response encoding isn't set:

- (NSStringEncoding) responseEncoding
{
    return responseEncoding || self.defaultResponseEncoding;
}

- (void) setResponseEncoding:(NSStringEncoding)_responseEncoding
{
    responseEncoding = _responseEncoding;
}

There's also a more specific workaround for the getResponseString method, which I think is the only place that uses the encoding without checking for a value - since the encoding should be set for any non-zero length response:

- (NSString *)responseString
{
    NSData *data = [self responseData];
    if (!data) {
        return nil;
    }
    // --- INSERT THIS BLOCK ---
    // If the 'data' is present but empty, return a simple empty string
    if (data.length == 0) {
        return @"";
    }
    //assert(self.responseEncoding); // if you're into runtime asserts, uncomment this
    // --- END OF BLOCK TO INSERT ---
    return [[[NSString alloc] initWithBytes:[data bytes] length:[data length] encoding:[self responseEncoding]] autorelease];
}
like image 184
rvalue Avatar answered Oct 13 '22 11:10

rvalue


For me the problem was timeout wasn't enough. So it returns an empty response. So it gives this error because you'r trying to do something with an empty response. I increased the time for it. So it solved my problem.[request setTimeOutSeconds:200];

like image 34
e.ozmen Avatar answered Oct 13 '22 09:10

e.ozmen