5

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

5 Answers5

5

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];
}
bradley.ayers
  • 37,165
  • 14
  • 93
  • 99
rvalue
  • 2,652
  • 1
  • 25
  • 31
3

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];

e.ozmen
  • 269
  • 3
  • 17
1

this is just saying that the encoding was nil, when a value was expected. Try doing a search for "encoding:nil" or "encoding:NULL" in your source code and replace it with a valid encoding, for example NSStringEncodingASCII...

ecume des jours
  • 2,493
  • 1
  • 19
  • 15
0

This looks like something that's cropped up in the 4.2 SDK. I didn't see this until I updated my development environment myself.

All-Seeing Interactive will probably have to update the code to ensure compatibility.

-1

The error is where you are creating a string. You don't supply an encoding which is required.

TechZen
  • 64,370
  • 15
  • 118
  • 145
  • Yes i know that but the problem is that i am fetching xml data from server from the link i mentioned in my question, the async request is failing by given that error message, now i don't understand when similar calls with exact same schema for the data i am fetching is working perfectly and this only one request to this particular url is failing. – Syed Arsalan Pervez Dec 02 '10 at 05:12